Under the window if it is an empty window XP is normal, but now the window is very complex, there are a number of controls, Windows 7 is normal, XP will return 1,
BOOL CtestApp: : InitInstance ()
{
CWinApp: : InitInstance ();
Thread_Init ();
return TRUE;
}
Void CtestApp: : thread_Init ()
{
The CloseHandle ((HANDLE) _beginthreadex (NULL, 0, (unsigned int (__stdcall *) (void *)) & amp; Thread_main, NULL, 0, NULL));
}
Unsigned int __stdcall CtestApp: : thread_main (void * p)
{
//create a new dialog object
PTestUI=new CDlg1;
//AFX_MANAGE_STATE (AfxGetStaticModuleState ());
//HINSTANCE hResOld=AfxGetResourceHandle ();
//AfxSetResourceHandle (theApp m_hInstance);
DbgPrint (" pTestUI=% X "ready to open the window, pTestUI);
INT_PTR nResponse=pTestUI - & gt; DoModal ();
If (nResponse==IDOK)
{
//TODO: when placed in the treatment with
//"ok" to close the dialog box code
DbgPrint (" open window success ");
}
Else if (nResponse==IDCANCEL)
{
//TODO: when placed in the treatment with
//"cancel" to close the dialog box code
DbgPrint (" open window failed ");
}
Else if (nResponse==1)
{
DWORD nErr=: : GetLastError ();
DbgPrint (" X "open the window to terminate %, nErr);
TRACE (traceAppMsg, 0, "warning: failed to create dialog, the application will terminate unexpectedly, \ n");
TRACE (traceAppMsg, 0, "warning: if you are to use the MFC dialog box controls, there is no # define _AFX_NO_MFC_CONTROLS_IN_DIALOGS, \ n");
}
//AfxSetResourceHandle (hResOld);
DbgPrint (" open the window to complete the ");
The delete pTestUI;
: : FreeLibraryAndExitThread (theApp m_hInstance, 1);
return 0;
}
CodePudding user response:
Thread may need to initialize the COMCoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
//your code
.
CoUninitialize ();
CodePudding user response:
Some controls whether the initialization in a thread for a startCodePudding user response:
DoModal Debug F11 to look, where failed?CodePudding user response: