
常用软件类: |
|杀毒安全 | |联络聊天 | |网络软件 | |多媒体类 | |系统工具 | |图形图像 | |系统工具 | |应用软件 | |行业软件 |
开发设计类: |
|动画制作 | |图像处理 | |3D设计 | |操作系统 | |站长学院 | |网络相关 | |WEB设计 | |数据库类 | |程序开发 |
| DLL类型 | 入口函数 |
| 非 MFC DLL | 编程者提供DllMain函数 |
| MFC规则 DLL | CWinApp对象的InitInstance 和 ExitInstance |
| MFC扩展 DLL | MFC DLL向导生成DllMain 函数 |
| 宏 | 定义 |
| AFX_CLASS_IMPORT | __declspec(dllexport) |
| AFX_API_IMPORT | __declspec(dllexport) |
| AFX_DATA_IMPORT | __declspec(dllexport) |
| AFX_CLASS_EXPORT | __declspec(dllexport) |
| AFX_API_EXPORT | __declspec(dllexport) |
| AFX_DATA_EXPORT | __declspec(dllexport) |
| AFX_EXT_CLASS | #ifdef _AFXEXT AFX_CLASS_EXPORT #else AFX_CLASS_IMPORT |
| AFX_EXT_API | #ifdef _AFXEXT AFX_API_EXPORT #else AFX_API_IMPORT |
| AFX_EXT_DATA | #ifdef _AFXEXT AFX_DATA_EXPORT #else AFX_DATA_IMPORT |
| static AFX_EXTENSION_MODULE ExtDllDLL = { NULL, NULL }; extern "C" int APIENTRY DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved ) { // Remove this if you use lpReserved UNREFERENCED_PARAMETER( lpReserved ); //说明:lpReserved是一个被系统所保留的参数,对于隐式链接是一个非零值,对于显式链接值是零 if (dwReason == DLL_PROCESS_ATTACH) { TRACE0( "EXTDLL.DLL Initializing!\n" ); // Extension DLL one-time initialization if ( !AfxInitExtensionModule( ExtDllDLL, hInstance )) return 0; // Insert this DLL into the resource chain new CDynLinkLibrary( ExtDllDLL ); } else if (dwReason == DLL_PROCESS_DETACH) { TRACE0( "EXTDLL.DLL Terminating!\n" ); // Terminate the library before destructors are called AfxTermExtensionModule( ExtDllDLL ); } return 1; // ok } |
| struct AFX_EXTENSION_MODULE { BOOL bInitialized; HMODULE hModule; HMODULE hResource; CRuntimeClass* pFirstSharedClass; COleObjectFactory* pFirstSharedFactory; }; |
![]() 图15 MFC扩展DLL中的对话框 |
| class AFX_EXT_CLASS CExtDialog : public CDialog { public: CExtDialog( CWnd* pParent = NULL ); enum { IDD = IDD_DLL_DIALOG }; protected: virtual void DoDataExchange( CDataExchange* pDX ); DECLARE_MESSAGE_MAP() }; |
![]() 图16 MFC扩展DLL调用工程中的对话框 |
| // LoadExtDllDlg.cpp : implementation file // #include "..\ExtDialog.h" #pragma comment( lib, "ExtDll.lib" ) 而“调用DLL”按钮的单击事件的消息处理函数为: void CLoadExtDllDlg::OnDllcallButton() { CExtDialog extDialog; extDialog.DoModal(); } |
当我们单击“调用DLL”的时候,弹出了如图15的对话框。