Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Win32::API access violation

by brettc (Novice)
on May 31, 2001 at 03:53 UTC ( #84414=perlquestion: print w/replies, xml ) Need Help??
brettc has asked for the wisdom of the Perl Monks concerning the following question:

I a having Dr. Watson errors when using Win32::API. I have the following script function.
sub make_connection_to_job_controller($){ my($con_id) = @_; $job_controller_connection = new Win32::API('rlqs','rlqs_sender_co +nnect',[P],'I'); if(not defined $job_controller_connection){ die "\nCan't import API job_controller_connection: $!\n"; } $return_value_connect = $job_controller_connection->Call($con_id); if(!$return_value_connect){ die "\nSomething went wrong with connection.\nHere are the val +ues for return_value= $return_value\n"; } else{ print"\nSeems that the connection is made.\n"; print$return_value_connect; return $return_value; } }#end of make_connection_to_job_controller
I call the above function with this in a different file.
my $test=&make_connection_to_job_controller($connection);
When I run the file that makes the call to the function above I get a Dr. Watson Message after the $return_value_connect = $job_controller_connection->Call($con_id); is made and the program terminates. The DR. Watson error is as follows. Perl.exe Exception: access violation (0xc000005),Address;0x2893bb2e. and it never creates an application log entry. Does anyone have any Idea on how to fix this problem? I went through like a good coder and fixed all of the warnings now the program just fails. Have I missed something? I am using This is perl, v5.6.1 built for MSWin32-x86-multi-thread build from active state and the Win32::API from the same place. Thanks in advance Humble perl guy. Brett

Replies are listed 'Best First'.
(tye)Re: Win32::API access violation
by tye (Sage) on May 31, 2001 at 07:19 UTC

    Never use the "P" type for the return value unless you are sure the return value will always be '\0'-terminated string (and not what Microsoft calls "Unicode"). If it might be NULL or might be some other type of data, then you have to use the "N" type for the return value.

    If the value returned is 0, then you got a NULL. If not, and you are sure it is a pointer to a '\0'-terminated string, then you can use: my $string= unpack "p", pack "L", $ret;
    to get the string.

    Update: While everything I said above is good advice, none of it applies to this problem. ): I read the arguments to Win32::API->new() in the wrong order. "P" is being used for the first argument, not the return value.

    The only reason I can think that this might "core dump" is if you have the argument list types wrong or that you pass in a numeric 0 for the ID (and the function doesn't expect a NULL). Perhaps you could post the interface spec for the routine you are calling (since it appears to be a custom DLL, perhaps you could even post the code for that routine).

            - tye (but my friends call me "Tye")
Re: Win32::API access violation
by John M. Dlugosz (Monsignor) on Jun 01, 2001 at 06:20 UTC
    I don't know what rlqs_sender_connect is, but you might want to look at the parameter list for that. Is the marameter to your sub packed into the kind of structure it wants a pointer to, and are any of those members themselves pointers?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://84414]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2017-05-28 13:58 GMT
Find Nodes?
    Voting Booth?