Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi, need your help. Out my depth here (.NET developer well out of his comfort zone).
Ok quick summary: Got a third party DLL that goes to the internet for some information and takes about 2 minutes to do it. I need to use this DLL from my application but cant afford the 2 minute hit as my application will be called billions of times a nano
second (approx). So I want to have my application call a custom DLL that then calls the third party DLL, caching the returned data so future calls come instantly from the cache.
Getting the error message.
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.
and after some investigation its down to a calling convention mismatch between how the function pointer is defined and the calling conventions in the third party DLL functions. I have absolutely no idea how to fix it! none! and its annoying because I must
be close. Can you help?
Some code, that will help... ok my application calls a custom DLL with exports its functions like this, this is the same calling convention as the third party dll.

#define CMDB1_EXPORTS __declspec(dllexport)<br/>
<br/>
extern "C" CMDB1_EXPORTS int CM_GetDid(char* did);
CMDB1_EXPORTS int CM_GetDid(char* did)<br/>
{<br/>
// implementation will follow<br/>
}

This is called fine. No problem. This custom DLL now needs to call the third party DLL, I dont have lib files so I use LoadLibrary which is called from the DLLMain.
BOOL APIENTRY DllMain( HMODULE hModule,<br/>
DWORD ul_reason_for_call,<br/>
LPVOID lpReserved<br/>
)<br/>
{<br/>
switch (ul_reason_for_call)<br/>
{<br/>
case DLL_PROCESS_ATTACH:<br/>
hMod = LoadLibrary(L"TPD.DLL");<br/>
break;<br/>
case DLL_THREAD_ATTACH:<br/>
break;<br/>
case DLL_THREAD_DETACH:<br/>
break;<br/>
case DLL_PROCESS_DETACH:<br/>
FreeLibrary(hMod); <br/>
break;<br/>
}<br/>
return TRUE;<br/>
}
and then my DLL calls the same named methods from the third party DLL like this...
typedef int (*CC)(char*);
CMDB1_EXPORTS int CM_GetDid(char* did)<br/>
{
// has cached data?<br/>
CC pPA = (CC) GetProcAddress(hMod, "CM_GetDid");
// cache data in here
return (pPA) (did); // or cached data<br/>
}

Hope that explains things, not sure if the change would be in the typedef or the GetProcAddress code.
Basically the methods in the third party DLL should be the exact same calling convention as my exported functions.

Can you help?




<
"The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds his castles in the air, from air, creating by exertion of the imagination." - Fred Brooks<br/>
<br/>
<br/>

View the full article
 
Back
Top