Пример #1
0
BOOL WINAPI DllMain( 
					 HINSTANCE hinstDLL,	// handle to DLL module
					 DWORD fdwReason,		// reason for calling function
					 LPVOID lpReserved		// reserved
				   )  
{
	BOOL	fInit = FALSE;
	WORD	wVersionRequested;
	WSADATA wsaData;

    // Perform actions based on the reason for calling.
    switch( fdwReason ) 
    { 
        case DLL_PROCESS_ATTACH:

#ifndef _UNICODE
			OutputDebugStringA("--> dll_entry.c - oRTP.dll - DLL_PROCESS_ATTACH()\n");
#else
			OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - DLL_PROCESS_ATTACH()\n");
#endif
		 
			wVersionRequested = MAKEWORD( 1, 0 );

			if (WSAStartup(wVersionRequested,&wsaData)!=0) 
			{
				return FALSE;
			}

#ifdef ORTP_WINDOWS_DESKTOP
            // Create a named file mapping object. 
            hMapObject = CreateFileMapping( INVALID_HANDLE_VALUE,	// use paging file
											NULL,					// default security attributes
											PAGE_READWRITE,			// read/write access
											0,						// size: high 32-bits
											SHMEMSIZE,				// size: low 32-bits
											"oRTPSharedMemory");  // name of map object

            if (hMapObject == NULL) 
                return FALSE; 
 
            // The first process to attach initializes memory. 
            fInit = (GetLastError() != ERROR_ALREADY_EXISTS); 
 
            // Get a pointer to the file-mapped shared memory.
 
            lpSharedData = (LPSHARED_DATA) MapViewOfFile(   hMapObject,     // object to map view of
														   	FILE_MAP_WRITE, // read/write access
															0,              // high offset:  map from
															0,              // low offset:   beginning
															0);             // default: map entire file
            if (lpSharedData == NULL) 
                return FALSE; 
#else
			fInit = TRUE;
			lpSharedData = &sharedData;
#endif
 
            // Initialize memory if this is the first process.
 
            if (fInit) 
			{
#ifndef _UNICODE
				OutputDebugStringA("--> dll_entry.c - oRTP.dll - Initializing module\n");
#else
				OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - Initializing module\n");
#endif

#ifdef ORTP_WINDOWS_DESKTOP
				lpSharedData->m_dwStartTime	= GetTickCount();
#else
				lpSharedData->m_ullStartTime = GetTickCount64();
#endif
				lpSharedData->m_nReference	= 1;
				lpSharedData->m_bInitialize = FALSE;

				// Register the log
				RegisterLog(&dwoRTPLogLevel, "LOG_ORTP");
			}
			else
			{
#ifndef _UNICODE
				OutputDebugStringA("--> dll_entry.c - oRTP.dll - Binding\n");
#else
				OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - Binding\n");
#endif
				lpSharedData->m_nReference++;
			}
            break;

        case DLL_THREAD_ATTACH:

			if (lpSharedData != NULL)
			{
				if (lpSharedData->m_bInitialize == FALSE)
				{
					// Initialize oRTP
					ortp_init();

					// Start the scheduler
					//ortp_scheduler_init();

					lpSharedData->m_bInitialize = TRUE;
				}
			}
            break;

        case DLL_THREAD_DETACH:
			break;

        case DLL_PROCESS_DETACH:

			if (lpSharedData != NULL)
			{
#ifndef _UNICODE
				OutputDebugStringA("--> dll_entry.c - oRTP.dll - Binding\n");
#else
				OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - Binding\n");
#endif
				lpSharedData->m_nReference--;

				if (lpSharedData->m_nReference == 0)
				{
#ifndef _UNICODE
					OutputDebugStringA("--> dll_entry.c - oRTP.dll - Detaching\n");
#else
					OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - Detaching\n");
#endif

					ortp_exit();
					UnregisterLog(&dwoRTPLogLevel, "LOG_ORTP");

#ifdef ORTP_WINDOWS_DESKTOP
					// Unmap shared memory from the process's address space. 
					UnmapViewOfFile(lpSharedData);
					lpSharedData = NULL;
	 
					// Close the process's handle to the file-mapping object.
					CloseHandle(hMapObject); 
					hMapObject = INVALID_HANDLE_VALUE;
#endif
				}
			}
            break;
    }

    return TRUE;  // Successful DLL_PROCESS_ATTACH.
}
Пример #2
0
BOOL CCommTestApp::InitInstance()
{
	// 如果一个运行在 Windows XP 上的应用程序清单指定要
	// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
	//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// 将它设置为包括所有要在应用程序中使用的
	// 公共控件类。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	// 初始化 OLE 库
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}
	
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	AfxEnableControlContainer();

	globalData.SetDPIAware ();

	// 标准初始化
	// 如果未使用这些功能并希望减小
	// 最终可执行文件的大小,则应移除下列
	// 不需要的特定初始化例程
	// 更改用于存储设置的注册表项
	// TODO: 应适当修改该字符串,
	// 例如修改为公司或组织名
	SetRegistryKey(_T("CommTestStudio"));
//	LoadStdProfileSettings(4);  // 加载标准 INI 文件选项(包括 MRU)
	SetRegistryBase (_T("Settings"));

	InitContextMenuManager();

	InitKeyboardManager();

	InitTooltipManager();
	CBCGPToolTipParams ttParams;
	ttParams.m_bVislManagerTheme = TRUE;
	theApp.GetTooltipManager()->SetTooltipParams(BCGP_TOOLTIP_TYPE_ALL,
		RUNTIME_CLASS(CBCGPToolTipCtrl), &ttParams);

	// 注册应用程序的文档模板。文档模板
	// 将用作文档、框架窗口和视图之间的连接
	RegisterLog( _T("MAIN"));

	m_pDocTemplate = new CMultiDocTemplate(IDR_CommTestTYPE,
		RUNTIME_CLASS(CCommTestDoc),
		RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
		RUNTIME_CLASS(CCommTestView));
	if (!m_pDocTemplate)
		return FALSE;
	AddDocTemplate(m_pDocTemplate);

	m_pPingDocTemplate = new CMultiDocTemplate(IDR_PING_TEST,
		RUNTIME_CLASS(CPingTestDoc),
		RUNTIME_CLASS(CPingChildFrame), // 自定义 MDI 子框架
		RUNTIME_CLASS(CPingOptionView));
	if (!m_pPingDocTemplate)
		return FALSE;
	AddDocTemplate(m_pPingDocTemplate);

	m_pClientDocTemplate = new CMultiDocTemplate(IDR_CLIENT_COMM,
		RUNTIME_CLASS(CClientCommDoc),
		RUNTIME_CLASS(CClientChildFrame), // 自定义 MDI 子框架
		RUNTIME_CLASS(CClientOptionView));
	if (!m_pClientDocTemplate)
		return FALSE;

	AddDocTemplate(m_pClientDocTemplate);

	m_pSvrDocTemplate = new CMultiDocTemplate(IDR_SVR_COMM,
		RUNTIME_CLASS(CSvrCommDoc),
		RUNTIME_CLASS(CSvrChildFrame), // 自定义 MDI 子框架
		RUNTIME_CLASS(CSvrOptionView));
	if (!m_pSvrDocTemplate)
		return FALSE;

	AddDocTemplate(m_pSvrDocTemplate);

	// 创建主 MDI 框架窗口
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
	{
		delete pMainFrame;
		return FALSE;
	}
	m_pMainWnd = pMainFrame;
	// 仅当具有后缀时才调用 DragAcceptFiles
	//  在 MDI 应用程序中,这应在设置 m_pMainWnd 之后立即发生


	// 分析标准外壳命令、DDE、打开文件操作的命令行
	CCommandLineInfo cmdInfo;
	cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
	ParseCommandLine(cmdInfo);


	// 调度在命令行中指定的命令。如果
	// 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
	// 主窗口已初始化,因此显示它并对其进行更新
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	return TRUE;
}