Jump to content
  • Advertisement

Archived

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

_the_phantom_

ESP not being reset properly...

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

If you intended to correct an error in the post then please contact us.

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 :)

	HMODULE loaderui = LoadLibrary("loaderui.dll");
	if (loaderui == NULL)
	{
		// flag error

		// probably dialog box

	}
	else
	{
		InitDLL  =  (tIDLLD)GetProcAddress( loaderui, "InitDLL" );  // InitDLL (entry point)

		nRet = InitDLL(hInstance,lpstrCmdLine,nCmdShow);
	}
	FreeLibrary(loaderui);
...
}
  
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("Fader Log", NULL,0);
	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);



	WriteLog("::InitDLL ","Starting Thread",1);


	CloaderThreadManager mgr;
	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 this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!