Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Correct call for dll with Win32::API

by walto (Pilgrim)
on Dec 04, 2008 at 20:15 UTC ( #728080=note: print w/replies, xml ) Need Help??


in reply to Re: Correct call for dll with Win32::API
in thread Correct call for dll with Win32::API

This is the line from the sample C-code:
int HCE300_Read(int TrackNo, char *ReadData);

I have no readable documentation of the dll. The data is read from an usb device. Re-reading the documentation of Win32::API I changed the line to:
my $readdevice = Win32::API->new ( 'HCE300_API.DLL', 'HCE300_Read','NP','N') or die $ +^E; if(not defined $readdevice) { die "Can't import API HCE_Read: $!\n"; }
I am not sure what it does, but it did not help. Perl still crashes.

Replies are listed 'Best First'.
Re^3: Correct call for dll with Win32::API
by ikegami (Pope) on Dec 04, 2008 at 20:24 UTC

    If int HCE300_Read(int TrackNo, char *ReadData); is the prototype, then it uses the default calling convention. It my understanding that's __cdecl for MS compilers. Win32::API uses the __stdcall calling convention since that's what the Win32 API (kernel32.dll, etc) uses.

    Argument-passing orderStack-maintenance responsibility
    __stdcallRight to leftCalled function pops its own arguments from the stack
    __cdeclRight to leftCalling function pops the arguments from the stack

    Win32::API expects the DLL function to reset the stack, but the DLL function expects its caller to reset the stack.

      Thanks for your help and patience with my lack of C, but does this mean I can not use Win32::API?

        If there's a difference in calling conventions, yes. Unresolvable protocol differences.

        It could be a number of other things too.

        • You have the wrong prototype.
        • You are using the library in a manner it doesn't expect.
        • There's a bug in the library.
        • etc.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://728080]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2021-01-27 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?