I plan to compile a Firefox plug-in. First, let's take a look at the examples provided on the official website.
: Http://mxr.mozilla.org/seamonkey/source/modules/plugin/samples/npruntime/
Download Method: I tried SVN, but I had to manually click each file in the project. A box is displayed in the upper right corner of the page, including CVS Log, CVS Blame, CVS Graph, diff file, Raw file. Select Raw file and save it
Compile the project as instructed on the web page: https://developer.mozilla.org/en/Compiling_The_npruntime_Sample_Plugin_in_Visual_Studio
If an error occurs after compilation, check the Version Issues at the bottom of the page.
After the compilation is successful, I will make some modifications, because test.htm In the example is too old.
Modify the Invoke function in plugin. cpp to block the code in the original function.
Bool <br/> ScriptablePluginObject: Invoke (NPIdentifier name, const NPVariant * args, <br/> uint32_t argCount, NPVariant * result) <br/>{< br/> if (name = sFoo_id) {<br/> printf ("foo called! /N "); <br/> MessageBox (NULL, L" foo called ", L" Promopt ", MB_ OK); <br/> return PR_TRUE; <br/>}< br/> return PR_FALSE; <br/>}< br/>
Modify the Invoke function to the pop-up dialog box.
Modify the test.htm file
<HTML> <br/> <pead> <br/> <title> Scriptable plug-in test </title> <br/> </pead> <br/> <body id = "bodyid"> <br/> <center> <br/> <p> sample Scriptable plug-in </p> <br/> </center> <br/> <br/> <center> <br/> <Div id = "result"> <br/> <p> results go here: </P> <br/> </div> <br/> <embed id = "embed1" name = "mypi" type = "application/Mozilla-npruntime-Scriptable-plugin "width = 600 Height = 40> <br/> <MCE: script Type =" Text/JavaScript "> <! -- <Br/> var embed1 = document. getelementbyid ('embedded 1'); <br/> // --> </MCE: SCRIPT> <br/> <form name = "formname"> <br/> <input type = button value = "alert (embed1.foo ()" onclick = 'embed1. foo () '> <br/> <input type = button value = "Call pluginobj. foo () "onclick = 'ininobj. foo () '> <br/> <input type = button value = "alert (mypi. foo () "onclick = 'document. mypi. foo () '> <br/> <input type = button value = "alert (pluginobj. bar) "onclick = 'alert (pluginobj. bar) '> <br/> </form> <br/> </center> <br/> </body> <br/> </ptml>
There are three methods in this example to obtain the plug-in and then call the foo function. A dialog box is displayed. The last button is used to obtain the property value.