Re: DLL import

From: wolfgang kern (nowhere_at_nevernet.at)
Date: 10/19/04


Date: Tue, 19 Oct 2004 20:55:49 +0000 (UTC)


"Marsupilami" wrote:

Regardless which calling convention is used,
the stack (the pushed parameters) have to be cleared after.
Either the 'callee' with a 'ret 8' (4 per parameter), if fn is a procedure,
or the 'caller' with an 'add esp,8' after the call, if fn is a call-back.
I think DLL-functions should work as procedures.
__
wolfgang

| I didn't fight with ASM/C for a long time, so, plz, don't laugh.
| This is a mini-DLL and very basic code (MASM) :
|
| =====
|
| .586
| .MODEL FLAT,STDCALL
|
| OPTION CASEMAP:NONE
|
| .data
| .code
|
| DllEntry proc hInstDLL:DWORD, reason:DWORD, reserved1:DWORD
| mov eax,1
| ret
| DllEntry Endp
|
| Addxy proc A:DWORD, B:DWORD
| mov eax,A
| add eax,B
| ret
| Addxy endp
|
| END DllEntry
|
| =====
|
| How do I call Addxy() from C/C++ code ?
|
| I tried :
|
| =====
|
| typedef int (_stdcall *Addxyproc)(int,int);
|
| Addxyproc addNumbers;
|
| HINSTANCE handle = LoadLibrary(DllName); // DllName is the path to the DLL
|
| addNumbers = (Addxyproc)GetProcAddress(handle,"Addxy");
|
| printf("x+y = %d\n", addNumbers(1,2));
|
| =====
|
| At runtime, when running the printf() instruction I get
|
| "Run-Time Check Failure #0 - The value of ESP was not properly saved across
| a function call. This is usually a result of calling a function declared
| with one calling convention with a function pointer declared with a
| different calling convention."
|
| Where's the stupid stuff I don't see...
|
| Thx for ur help.



Relevant Pages

  • DLL import
    ... DllEntry proc hInstDLL:DWORD, reason:DWORD, reserved1:DWORD ... DllEntry Endp ... Addxy proc A:DWORD, B:DWORD ... different calling convention." ...
    (comp.lang.asm.x86)
  • Re: Exporting function in VS2008 DLL
    ... #define DLLENTRY __declspec ... extern "C" {DLLENTRY int Foo;} ... Calling convention mismatch between DLL and a client is one of the ...
    (microsoft.public.vc.language)