コード例 #1
0
ファイル: winthred.cpp プロジェクト: Ukusbobra/open-watcom-v2
DWORD WINAPI _WinThreadProc( LPVOID lpParameter )
/***********************************************/
{
    CWinThread *pThread = (CWinThread *)lpParameter;
    ASSERT( pThread != NULL );
    AFX_MODULE_THREAD_STATE *pState = AfxGetModuleThreadState();
    ASSERT( pState != NULL );
    ASSERT( pState->m_pCurrentWinThread == NULL );
    pState->m_pCurrentWinThread = pThread;
    AfxInitThread();
    int nExitCode;
    if( pThread->m_pfnThreadProc != NULL ) {
        nExitCode = pThread->m_pfnThreadProc( pThread->m_pThreadParams );
    } else {
        if( pThread->InitInstance() ) {
            nExitCode = pThread->Run();
        } else {
            nExitCode = -1;
        }
    }
    if( pThread->m_bAutoDelete ) {
        delete pThread;
    }
    AfxTermThread( NULL );
    return( nExitCode );
}
コード例 #2
0
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPTSTR lpCmdLine, int nCmdShow)
{
	ASSERT(hPrevInstance == NULL);

	int nReturnCode = -1;
	__try
	{
	CWinThread* pThread = AfxGetThread();
	CWinApp* pApp = AfxGetApp();

	// AFX internal initialization
	if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
		goto InitFailure;

	// App global initializations (rare)
	if (pApp != NULL && !pApp->InitApplication())
		goto InitFailure;

	// Perform specific initializations
	if (!pThread->InitInstance())
	{
		if (pThread->m_pMainWnd != NULL)
		{
			TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n");
			pThread->m_pMainWnd->DestroyWindow();
		}
		nReturnCode = pThread->ExitInstance();
		goto InitFailure;
	}
	nReturnCode = pThread->Run();

InitFailure:
#ifdef _DEBUG
	// Check for missing AfxLockTempMap calls
	if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
	{
		TRACE(traceAppMsg, 0, "Warning: Temp map lock count non-zero (%ld).\n",
			AfxGetModuleThreadState()->m_nTempMapLock);
	}
	AfxLockTempMaps();
	AfxUnlockTempMaps(-1);
#else
	;
#endif
	}
	__except(RecordExceptionInfo(GetExceptionInformation()))
	{
	}

	// must call AfxWinTerm after handling exception or we'll crash
	// again trying to destroy the tooltip window

	AfxWinTerm();

	return nReturnCode;
}