12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- // AutoRobot.cpp : 定义 DLL 的初始化例程。
- //
- #include "stdafx.h"
- #include <afxdllx.h>
- #include "AutoRobot.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // --以下是全局导出对象--;
- CSerialFactory *pSerialImpl = NULL;
- // 全局唯一性变量;
- HWND ghWnd = NULL; // 程序主窗口句柄;
- vector <STRecvMessage> g_vtRecv; // 数据池;
- CRITICAL_SECTION g_cs_vt; // 数据池操作的临界值;
- DWORD g_dwCID = 0; // 数据池元素的ID;
- static AFX_EXTENSION_MODULE AutoRobotDLL = { NULL, NULL };
- extern "C" int APIENTRY
- DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
- {
- // 如果使用 lpReserved,请将此移除
- UNREFERENCED_PARAMETER(lpReserved);
- if (dwReason == DLL_PROCESS_ATTACH)
- {
- TRACE0("AutoRobot.DLL 正在初始化!\n");
-
- // 扩展 DLL 一次性初始化
- if (!AfxInitExtensionModule(AutoRobotDLL, hInstance))
- return 0;
- // 将此 DLL 插入到资源链中
- // 注意: 如果此扩展 DLL 由
- // MFC 规则 DLL(如 ActiveX 控件)隐式链接到
- // 而不是由 MFC 应用程序链接到,则需要
- // 将此行从 DllMain 中移除并将其放置在一个
- // 从此扩展 DLL 导出的单独的函数中。使用此扩展 DLL 的
- // 规则 DLL 然后应显式
- // 调用该函数以初始化此扩展 DLL。否则,
- // CDynLinkLibrary 对象不会附加到
- // 规则 DLL 的资源链,并将导致严重的
- // 问题。
- new CDynLinkLibrary(AutoRobotDLL);
- }
- else if (dwReason == DLL_PROCESS_DETACH)
- {
- TRACE0("AutoRobot.DLL 正在终止!\n");
- // 在调用析构函数之前终止该库
- AfxTermExtensionModule(AutoRobotDLL);
- }
- return 1; // 确定
- }
- void CreateSerialImpl(void)
- {
- if ( pSerialImpl == NULL )
- {
- pSerialImpl = new CSerialFactory;
- }
- }
- BOOL GetMainWnd(HWND &hwnd)
- {
- if ( hwnd == NULL )
- return FALSE;
-
- ghWnd = hwnd;
-
- return TRUE;
- }
|