What wrong happened in my simple dll?
-
----------------- TestDll.h ----------------- #ifdef __cplusplus #define EXPORT extern "C" __declspec (dllexport) #else #define EXPORT __declspec (dllexport) #endif EXPORT BOOL Test1(BOOL b1); ----------------- TestDll.c ----------------- #include "SocketDll.h" int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) { return TRUE; } EXPORT BOOL Test1(BOOL b1) { return b1; } ====================================================== When my application calls the Test1() function, error occurred. It reports : ----------------------------------------------------------------- file: i386\chkesp.c line:42 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. ----------------------------------------------------------------- But if the Test1() function has no argument, it works. I don't know how to correct it.
-
----------------- TestDll.h ----------------- #ifdef __cplusplus #define EXPORT extern "C" __declspec (dllexport) #else #define EXPORT __declspec (dllexport) #endif EXPORT BOOL Test1(BOOL b1); ----------------- TestDll.c ----------------- #include "SocketDll.h" int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) { return TRUE; } EXPORT BOOL Test1(BOOL b1) { return b1; } ====================================================== When my application calls the Test1() function, error occurred. It reports : ----------------------------------------------------------------- file: i386\chkesp.c line:42 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. ----------------------------------------------------------------- But if the Test1() function has no argument, it works. I don't know how to correct it.
> When my application calls the Test1() function, error occurred. > It reports : > ----------------------------------------------------------------- > file: i386\chkesp.c line:42 > 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. Hm...maybe you compiled your EXE with a different calling convention than your DLL? In VC6, check the following: Project -> Settings (or Alt+F7) -> C/C++ Tab -> Category: Code Generation -> Calling Convention You can also modify the calling convention of each function individually; i.e., try out all the combinations:
EXPORT BOOL __stdcall Test1(BOOL b1) { return b1; }
EXPORT BOOL __cdecl Test1(BOOL b1) { return b1; }
EXPORT BOOL __fastcall Test1(BOOL b1) { return b1; }> When my application calls the Test1...() Anyway, is your EXE a VB application? Then you'll have to declare the exported function with __stdcall. It's the only calling convention known by VB. Regards, RK