Home > Software engineering >  [for] DoModal under Windows 7 (normal), under the XP DoModal () returns 1
[for] DoModal under Windows 7 (normal), under the XP DoModal () returns 1

Time:10-12

As title, MFC DLL in thread to create a new window, paste the code, please the great god to analyze the possible reasons of
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 COM
CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
//your code
.
CoUninitialize ();

CodePudding user response:

Some controls whether the initialization in a thread for a start

CodePudding user response:

DoModal Debug F11 to look, where failed?

CodePudding user response:

reference VisualEleven reply: 3/f
DoModal Debug F11 to look, where failed?

Program was developed by using VS2013 under Windows 7, while the virtual machine with xp, but VS2013 not, so can't debugging,

CodePudding user response:

reference 1st floor zgl7903 response:
thread words may need to initialize the COM
CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
//your code
.
CoUninitialize ();

Don't use other third-party plug-ins in application development? Is the system need to initialize the COM components?
  • Related