#### Archived

This topic is now archived and is closed to further replies.

# ESP not being reset properly...

This topic is 5560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ve got a slight problem, i''ve got some code in a dll i wanna run from an exe, now with the exe and dll binded togeter normal it all works fine, however for patching reasons I want the loader program to be able to dynamical bind to the dll to call its init function. I added the code which I thought should do this, and the program all works fine, until this init function returns at which point I get an error saying ESP hasnt been reset properly, this is often due to the parameters parsed not matching the ones given. the relivent bits of code follow :

typedef int (__stdcall *tIDLLD)(HINSTANCE hInstance, LPTSTR lpstrCmdLine, int nCmdShow);

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
int nRet;
tIDLLD InitDLL;
...

// jump into DLL to do all my init work

// do it via LoadLib so we can unload stuff to patch :)

{
// flag error

// probably dialog box

}
else
{

nRet = InitDLL(hInstance,lpstrCmdLine,nCmdShow);
}
...
}

the function is found and bound correctly as it all works, however on return from the InitDLL call I get the error above... I dont THINK my calls are mismatched.. however.. Code for the function being called in the dll

extern "C" {

LOADERUI_API int InitDLL(HINSTANCE hInstance, LPTSTR lpstrCmdLine, int nCmdShow)
{
// Init''s the DLL

// TODO: deside if we want to us the DLL or exe''s hInstance here

// based on the calling functions init I _think_ we should be using the exe''s hInstance

WriteLog("---------------",NULL,0);
WriteLog(NULL,NULL,0);
WriteLog("::InitDLL ","Init AppModule",1);

HRESULT hRes = _Module.Init(NULL, hInstance);
ATLASSERT(SUCCEEDED(hRes));

//	int nRet = Run(lpstrCmdLine, nCmdShow);

int nRet = mgr.Run(lpstrCmdLine, nCmdShow);

WriteLog("::InitDLL ","Shutting Down",1);

_Module.Term();
return nRet;
}
}

WriteLog() is my own custom routines for log writing. I''m a bit lost as to whats up tbh, unless its related to this function being linked C and using C++ objects and called from a C++ linked function.. which truely is my last ''out there'' idea... i''ve no idea whats up.. any help muchly appricated

##### Share on other sites
ack, dont worry... I fixed it on my own... added __stdcall to the C function and changed the function call I was looking for to _InitDLL@4 (I''ve since changed the fucntion prototype to take a pointer) and its all working now...

amazing what a few hours away from the code will do for ya