DLL Calling convention problem
-
I started programming a "simple" DLL with dynamic linking from the main application via LoadLibrary , GetProcAddress (and the rest). Somewhere I make a trivial fault, which so far is difficult to correct. Everything goes well, but when the function is exected, i get the next message. Debug Error, File chkesp.c, line 41 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. This should give a clue, but it did not help me so far. To my understaning both my application and dll are compiled/linked with __cdecl as standard, so I'm lost now (but hope not for that long) Bert....
-
I started programming a "simple" DLL with dynamic linking from the main application via LoadLibrary , GetProcAddress (and the rest). Somewhere I make a trivial fault, which so far is difficult to correct. Everything goes well, but when the function is exected, i get the next message. Debug Error, File chkesp.c, line 41 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. This should give a clue, but it did not help me so far. To my understaning both my application and dll are compiled/linked with __cdecl as standard, so I'm lost now (but hope not for that long) Bert....
Have you tried following the function call through in the Debugger. A reasonable knowlodge of assembler would help here. Do you really need to dynamically load the DLL with LoadLibrary() and if so why? If it is a) because you don't want to waiste time loading until it is required, or b) you don't know if it exists, then using /DELAYLOAD with an SEH exception handler is a much better way to go. See: MSJ, December 1998 Win32 Q&A. http://www.microsoft.com/msj/1298/win32/win321298.aspx[^]for a good article on /DELAYLOAD. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
-
I started programming a "simple" DLL with dynamic linking from the main application via LoadLibrary , GetProcAddress (and the rest). Somewhere I make a trivial fault, which so far is difficult to correct. Everything goes well, but when the function is exected, i get the next message. Debug Error, File chkesp.c, line 41 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. This should give a clue, but it did not help me so far. To my understaning both my application and dll are compiled/linked with __cdecl as standard, so I'm lost now (but hope not for that long) Bert....
assuming you're exporting C functions (not C++ stuff) it might help to add ' extern "C" ' to the function declarations : DLL's header: extern "C" WINAPI void MyFunc(...); DLL's implementation: #include "DLLs header.h" ... void WINAPI MyFunc(...) { } -c
Chris Losinger
Smaller Animals Software