DLL import

From: Marsupilami (spamtrap_at_crayne.org)
Date: 10/19/04

  • Next message: Scott J. McCaughrin: "Re: math co-processor exceptions"
    Date: Tue, 19 Oct 2004 02:52:06 +0000 (UTC)
    
    

    Hi.

    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.


  • Next message: Scott J. McCaughrin: "Re: math co-processor exceptions"

    Relevant Pages

    • Re: DLL import
      ... Regardless which calling convention is used, ... | DllEntry proc hInstDLL:DWORD, reason:DWORD, reserved1:DWORD ... | Addxy proc A:DWORD, B:DWORD ...
      (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)