Problem with a injection MFC Dll

c++ / delphi package - dll injection and api hooking
Layane
Posts: 20
Joined: Sat May 01, 2004 11:03 am

Post by Layane »

After a week i resolve the problem with MFC Dlls. The source code that fix the problem is:

Code: Select all

CMyApplication theApp;

DWORD WINAPI ThreadStart (LPVOID dwThreadId) {
	::Sleep(300);

	//Change the module state
	AFX_MODULE_STATE *ModStat;

	ModStat = AfxGetStaticModuleState();
	ModStat->m_pCurrentWinApp = &theApp;
	ModStat->m_hCurrentInstanceHandle = ::GetModuleHandle(NULL);

	AFX_MANAGE_STATE(ModStat);

	//put the new params for us application
	theApp.m_hThread = ::GetCurrentThread();
	theApp.m_nThreadID = m_nThreadID;
	theApp.m_hInstance = ::GetModuleHandle(NULL);
                
	//We create the windows
	CFrameWnd *MainWin = new CFrameWnd();

	MainWin->Create(NULL,"Prueba");
	MainWin->ShowWindow(SW_SHOW);

	theApp.m_pMainWnd = MainWin;

	//Run the message loop
	theApp.Run();                

	return TRUE;
}

BOOL CMyApplication::InitInstance() 
{
	DWORD dwThreadId;

	::CreateThread(NULL,0,ThreadStart,0,0,&dwThreadId);
	
	return CWinApp::InitInstance();
}
Greatings:
- Madshi thks for the support and ideas to solve this problem :lol: :wink:

References:
- The bug: http://support.microsoft.com/default.as ... -US;142243
- MFC Source Code
Post Reply