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() }; |
文章评论(0条评论)
登录后参与讨论