Analyzing plug-in technology

zhaozj2021-02-08  233

Analyzing plug-in technology

Author: table

Mailto: Tablejiang@21cn.com

Reprint, 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. 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 * pmoducture; / / Initialization function void (* plugin_quit) (Struct pluginmodule * pmodule); // exits the function void (* plugin_run) (Struct pluginmodule * PModule); // Execute the function} PluginModule;

There is also the export function of the DLL:

Typedef Pluginmodule * (* getpluginmodule) ();

In this way, we define a plug-in 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

// function implementation module 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", pmodule-> author, mb_ok);}

This way, we define the interface function. 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,};

Then define the DLL export function // plug-in interface #IFDEF __CPLUSPLUS EXTERN "C" {#ENDIF

__Declspec (dllexport) pluginmodule * getpluginmodulefunction () {return & module;}

#ifdef __cplusplus} #ENDIF

In this way, 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 (). The performance function address PlugInMoudle comprising plug-in functionality so that it can reference void JhmDll_Config (struct PlugInModule * pModule); // Set function void JhmDll_Init (struct PlugInModule * pModule); // initialize function void JhmDll_Quit (struct PlugInModule * pModule); / / Exit function void jhmdll_run (struct pluginmodule * pmodule); // executes the function of these plug-in functions.

This is just a personal idea, if there is a different opinion, you can email. Welcome to discuss.

If you need more detailed content, you can go to http://wolfftp.51.net or http://mywolfsoft.51.net to download the demonstration source code.

转载请注明原文地址:https://www.9cbs.com/read-2262.html

New Post(0)