I want to open a MFC modeless dialog from a MFC dll injected into another process, the dll's job is to hook the winsock send & recv, and the dialog will be the interface to communicate with the dll. The dll should be able to run the hook while the dialog is running.
BOOL CDriverApp::InitInstance()
{
CWinApp::InitInstance();
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
AfxMessageBox("I'm In!");
DetourTransactionBegin();
DetourUpdateThread( GetCurrentThread() );
DetourAttach( &(PVOID &)RealSend, MySend );
DetourAttach( &(PVOID &)RealRecv, MyRecv );
if ((DetourTransactionCommit()) == NO_ERROR)
{
AfxMessageBox("Winsock hooked");
}
dlg = new ControlDlg();
m_pMainWnd = dlg;
if(dlg->Create(IDD_CONTROL_DLG))
{
dlg->ShowWindow(SW_SHOW);
}
//ExitThread(0);
return TRUE; <---
}
dlg
is the dialog which is a member of CDriverApp
From what i have observed, the dialog is destroyed because the thread has exited and the memory that hold the dialog is removed.
The thread '_DllMainCRTStartup' (0x418) has exited with code 1657602048 (0x62cd0000).
I have read MFC modeless dialog close immediately thread, but my InitInstance()
already returned true
from the first place, so it's a different problem (i think)
So, my question is how to prevent the dialog from destroyed? Or perhaps prevent the thread from exit? or is it doable with a modal dialog?