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 );
}
Exemple #2
0
int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,
                      int nCmdShow )
/**********************************/
{
    if( !AfxWinInit( hInstance, hPrevInstance, lpCmdLine, nCmdShow ) ) {
        return( -1 );
    }
    AfxInitThread();
    
    CWinApp *pApp = AfxGetApp();
    ASSERT( pApp != NULL );
    int nExitCode;
    if( !pApp->InitInstance() ) {
        nExitCode = -1;
    } else {
        nExitCode = pApp->Run();
    }
    AfxTermThread( hInstance );
    return( nExitCode );
}
Exemple #3
0
BOOL AFXAPI AfxWinInit(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
	_In_z_ LPTSTR lpCmdLine, _In_ int nCmdShow)
{
	ASSERT(hPrevInstance == NULL);


	// handle critical errors and avoid Windows message boxes
	SetErrorMode(SetErrorMode(0) |
		SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);

	// set resource handles
	AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
	pModuleState->m_hCurrentInstanceHandle = hInstance;
	pModuleState->m_hCurrentResourceHandle = hInstance;
	pModuleState->CreateActivationContext();

	// initialize thread specific data (for main thread)
	if (!afxContextIsDLL)
		AfxInitThread();

	return TRUE;
}