Analysis of plug-in technology: Prince mailto: tablejiang@21cn.com reproduced please ensure the integrity of the document. Many people are very interested in plug-in technology. I have studied some of the principles of the player's plug-in technology, and now write some experience. The insert principle is to call different modules by unified program interfaces to achieve different functions. The functionality used to expand the main program. Now let's talk about its implementation. The implementation of plug-in technology is generally defined first. This structure contains a pointer to the interface function to be referenced by the main program. Of course, the format of these interface functions must be defined in advance. In the plug-in DLL, only one export function is generally used, and the export function can be used to obtain a pointer to the interface structure. Such a main program can use the pointer to use the function in the plug-in module. For example: We first define the structure of the interface function: typedef struct pluginmodule {dword ver; // version char * author; // Author Description CHAR * DESCRIPTION; // Module Description Byte * InputPointer; // Input Data [IN / OUT] DWORD DWSIZE; / / Enter the size of the data [in] hwnd hparentWnd; // Parent window [in] hinstance hdllinst; // DLL handle [in] void (* plugin_config) (Struct pluginmodule * PModule); // Setting function void (* plugIn_Init) (struct PlugInModule * pModule); // initialize function void (* PlugIn_Quit) (struct PlugInModule * pModule); // exit function void (* PlugIn_Run) (struct PlugInModule * pModule); //} function is executed Pluginmodule; there is also a DLL export function: typedef pluginmodule * (* getpluginmodule) (); this defines a plugin interface. In the plugin DLL, it can be implemented like this. State and define interface functions.
// function definition void JhmDll_Config (struct PlugInModule * pModule); // Set function void JhmDll_Init (struct PlugInModule * pModule); // initialization function void JhmDll_Quit (struct PlugInModule * pModule); // exit function void JhmDll_Run (struct PlugInModule * pModule ); // Execute function // module functions Implement Void Jhmdll_config (Struct Pluginmodule * PModule) {char szdisplay [260]; Sprintf (SZDisplay, "% S, Config Module", PModule-> Description); MessageBox (Null, "config ", pmodule-> author, mb_ok);} void jhmdll_init (struct pluginmodule * pmodule) {char szdisplay [260]; sprintf (szdisplay,"% s, init module ", pmodule-> description); MessageBox (null," init ", pmodule-> author, mb_ok);} void jhmdll_quit (struct pluginmodule * pmodule) {char szdisplay [260]; sprintf (szdisplay,"% s, quit module ", pmodule-> description); MessageBox (null," quit ", pmodule-> author, mb_ok);} void jhmdll_run (struct pluginmodule * pmodule) {char szdisplay [260]; sprintf (szdisplay,"% s, run module ", pmodule-> description); MessageBox (Null," RUN ", PMODUL E-> Author, MB_OK);} This, we define the interface functions. Of course, we must join them to the interface structure. In this way, one interface structure is defined, while initializing: // Initializing the interface pluginmodule module = {0x0100, "Table.jhm. Prose", "Demonstration plug-in technology 1 - empty module", NULL, 0, NULL, NULL, JHMDLL_CONFIG , JhmDll_Init, JhmDll_Quit, JhmDll_Run,}; Dll then define exported functions // widget Interface #ifdef __cplusplusextern "C" {#endif__declspec (dllexport) PlugInModule * GetPlugInModuleFunction () {return & module;} # ifdef __cplusplus} #endif so The interface function of a plug-in DLL is complete, of course, you need to add your plugin function code in the interface function. Thus the main program is again transmitted by dynamically loading the DLL, the mapping export function addresses can get a PluginModule structure by exporting the function getPlugINModuleFunction ().