插件技术的实现,一般都是先定义好一个接口结构。这个结构包含了主程序要引用的接口函数的指针。当然,这些接口函数的格式必须是事先定义好了的。而在插件Dll中一般只有一个导出函数,利用这个导出函数,我们可以得到接口结构的指针。 这样主程序就可以通过指针来使用插件模块中的功能了。 举个例子: 我们先定义好包含接口函数的结构:typedef struct PlugInModule{DWORD Ver ; file://版/本char *Author ; file://作/者说明char *Description; file://模/块说明BYTE *InputPointer; file://输/入数据 [in/out]DWORD dwSize ; file://输/入数据的大小 [in]HWND hParentWnd ; file://父/窗口 [in]HINSTANCE hDllInst ; file://Dll/句柄 [in]void (*PlugIn_Config)( struct PlugInModule * pModule ) ; file://设/置函数void (*PlugIn_Init)( struct PlugInModule * pModule ) ; file://初/始化函数void (*PlugIn_Quit)( struct PlugInModule * pModule ) ; file://退/出函数void (*PlugIn_Run )( struct PlugInModule * pModule ) ; file://执/行函数} PlugInModule ;还有申明Dll的导出函数:typedef PlugInModule* (*GETPLUGINMODULE)();这样,我们就定义好了一个插件的接口。在插件Dll中,可以这样实现。申明和定义接口函数。file://函/数定义void JhmDll_Config( struct PlugInModule * pModule ) ; file://设/置函数void JhmDll_Init( struct PlugInModule * pModule ) ; file://初/始化函数void JhmDll_Quit( struct PlugInModule * pModule ) ; file://退/出函数void JhmDll_Run( struct PlugInModule * pModule ) ; file://执/行函数file://模/块函数实现void JhmDll_Config( struct PlugInModule * pModule ){char szDisplay[260] ;sprintf( szDisplay , "%s , config 模块" , pModule->Description ) ;MessageBox( NULL , "config" , pModule->Author , MB_OK ) ;}void JhmDll_Init( struct PlugInModule * pModule ){char szDisplay[260] ;sprintf( szDisplay , "%s , Init 模块" , pModule->Description ) ;MessageBox( NULL , "Init" , pModule->Author , MB_OK ) ;}void JhmDll_Quit( struct PlugInModule * pModule ){char szDisplay[260] ;sprintf( szDisplay , "%s , Quit 模块" , pModule->Description ) ;MessageBox( NULL , "Quit" , pModule->Author , MB_OK ) ;}void JhmDll_Run( struct PlugInModule * pModule ){char szDisplay[260] ;sprintf( szDisplay , "%s , Run 模块" , pModule->Description ) ;MessageBox( NULL , "Run" , pModule->Author , MB_OK ) ;}这样,我们就定义好了接口函数。当然,我们必须把它们加入到接口结构中去。这样,再定义一个接口结构,并同时初始化:file://初/始化接口PlugInModule module = {0x0100 ,"Table.JHM.太子" ,"示范插件技术1--空模块" ,NULL ,0 ,NULL ,NULL ,JhmDll_Config ,JhmDll_Init ,JhmDll_Quit ,JhmDll_Run ,};然后再定义Dll的导出函数file://插/件的接口#ifdef __cplusplusextern "C" {#endif__declspec( dllexport ) PlugInModule *GetPlugInModuleFunction(){return &module;}#ifdef __cplusplus}#endif这样,一个插件dll的接口功能就完成了,当然,你需要在接口函数中添加你的插件功能代码。这样主程序再通过动态加载Dll,映射导出函数地址, 就可以通过导出函数GetPlugInModuleFunction()得到一个PlugInModule结构的指针。而PlugInMoudle包含插件功能的功能函数地址,这样就可以引用void JhmDll_Config( struct PlugInModule * pModule ) ; file://设/置函数void JhmDll_Init( struct PlugInModule * pModule ) ; file://初/始化函数void JhmDll_Quit( struct PlugInModule * pModule ) ; file://退/出函数void JhmDll_Run( struct PlugInModule * pModule ) ; file://执/行函数这些插件函数的功能了。这只是个人想法,如果有不同意见的可以 email 。欢迎讨论。如果需要更详细的内容,大家可以到http://wolfftp.51.net/ 或 http://mywolfsoft.51.net/ 去下载示范源代码。