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

Is the calling convention used by the DLL the same as the one defined by the WINAPI define (__stdcall)?

I use this script

I don't believe you. 'int HCE300_Read(int TrackNo(int TrackNo,char *ReadData )'?

Replies are listed 'Best First'.
Re^2: Correct call for dll with Win32::API
by walto (Pilgrim) on Dec 04, 2008 at 20:15 UTC
    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.

      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?