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

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.

Replies are listed 'Best First'.
Re^4: Correct call for dll with Win32::API
by walto (Pilgrim) on Dec 04, 2008 at 20:38 UTC
    Thanks for your help and patience with my lack of C, but does this mean I can not use Win32::API?
        I installed Visual c++ and started dumpbin as you suggested. This is the output:
        Dump of file c:\Programme\HCE300B_APP\ApiLib\HCE300_API.dll File Type: DLL Section contains the following exports for HCE300_API.dll 00000000 characteristics 0 time date stamp Thu Jan 01 01:00:00 1970 0.00 version 1 ordinal base 14 number of functions 14 number of names ordinal hint RVA name 5 0 0005A51C HCE300_Break 13 1 0005B148 HCE300_Close 3 2 0005A514 HCE300_GetDeviceType 9 3 0005AFD8 HCE300_GetLastStatus 1 4 0005B2C8 HCE300_GetRecordFormat 2 5 0005B260 HCE300_GetTrack2Density 14 6 0005A52C HCE300_Open 11 7 0005A854 HCE300_Read 12 8 0005B174 HCE300_Reset 4 9 0005A4F0 HCE300_SetDeviceType 7 A 0005B268 HCE300_SetRecordFormat 6 B 0005A4D0 HCE300_SetShowDialog 8 C 0005B200 HCE300_SetTrack2Density 10 D 0005AC5C HCE300_Write Summary 1000 .edata 3000 .idata 6000 .reloc 1A000 .rsrc 2000 BSS 5B000 CODE 2000 DATA
        I also found some more C sample code:
        char ReadBuf[250]; /* Open Success */ if(HCE300_Read(2, ReadBuf) == HCE300_OK) { } else { }
        (I removed the unreadable chinese comments from the sample)

      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.