Compiling The npruntime Sample Plugin in Visual Studio

  • Revision slug: Compiling_The_npruntime_Sample_Plugin_in_Visual_Studio
  • Revision title: Compiling The npruntime Sample Plugin in Visual Studio
  • Revision id: 85670
  • Created:
  • Creator: toaarnio
  • Is current revision? No
  • Comment The VC++ compiler throws an error on 'DrawText' not 'DrawTextW'; 1 words added, 1 words removed

Revision Content

General decisions

  • filename of DLL
    must start with "np" (not "ns") and ends with ".dll" (I wasted hours on this - repeatedly)
  • mimetype
    reflects the data type handled by the plugin. this is how webpages invoke your plugin. should either be like "application/x-vnd-yourorganization-yourfiletype" or be officially registered with IANA (unlikely) or be a standard type (e.g. if you want to play MPEG files).
  • file extension
    reflects the data type handled by the plugin, esp. when loaded from local disk on Windows.

Build

  1. Create a new project in Visual Studio for a Win32 GUI library (DLL) (in .NET 2003: Win32 template, then switch to DLL in Application Settings in the following dialog, export symbols too?)(in Visual Studio 2008, it is Visualc++|Win32|Win32 Project, then check DLL in the wizard).
  2. If a wizard gives you a checkbox to create an empty project, then check it. Otherwise you'll delete files later.
  3. Again note that the resulting DLL filename must start with "np", so either call your project like this or rename the file later
  4. Delete the .cpp and .h and ReadMe files from the project and disk (if you did not create an empty project)
  5. Copy the npruntime sample plugin source code into the dir of the new VS project and add the files to the project using the VS GUI (.cpp files to "Source Files", .h files to "Header Files", .rc file to "Resource Files"). Samples can be obtained from: https://developer.mozilla.org/en/Plugins/Samples_and_Test_Cases
  6. Download the Gecko SDK (aka XULRunner SDK) from mozilla.org release FTP and extract it. You can download it from here: http://developer.mozilla.org/en/docs/Gecko_SDK
  7. Add the Gecko SDK include path (example : C:\xulrunner-sdk\sdk\include) to Project Properties|(all configurations)|C++|General|Additional Include Directories. Note: If your project is still empty, the C++ tree might not be visible. So, add some files first.
  8. Add the following preprocessor definitions to Project Properties|(all configurations)|C++|Preprocessor|Preprocessor Definitions: WIN32;_WINDOWS;XP_WIN32;MOZILLA_STRICT_API;XPCOM_GLUE;XP_WIN;_X86_;NPSIMPLE_EXPORTS
  9. Disable precompiled headers using Project Properties|(all configurations)|C++|Precompiled headers|Create/Use precompiled header. They may be already disabled.
  10. Define the function exports by adding the .def filename (e.g. nprt.def) to Project Properties|(all configurations)|Linker|Input|Module Definition File. It could be either the full path or the path relative to the project directory.
  11. Optional: Open the above .def file and change "NPRT" to the filename of your dll as VS sees it (without "np", if you decided to rename later)
  12. Optional: Edit the .rc file and and the top of npp_gate.cpp for the description, mimetype, file extension etc. to reflect your plugin
  13. Remove the function NPP_GetJavaClass from npp_gate.cpp
  14. Build
  15. Rename the resulting DLL so that the filename starts with "np" and ends with ".dll" (or "32.dll"? 8.3?) and copy it in Mozilla's "plugins" folder
  16. Start Mozilla and open about:plugins to verify the plugin is detected
  17. Open the file "test.html" and begin testing. Make sure the mimetypes of your html embed tags match the mimetype specified in your nprt.rc file and the top of your npp_gate.cpp file

Version Issues

  1. If you are using Gecko SDK v1.9 and higher, you'll probably need to add folders \plugin, \nspr, and \java as included directories (as seen above, go to Project Properties|(all configurations)|C++|General|Additional Include Directories). These directories are contained in the Gecko SDK include path that you previously added.
  2. If VC++ compiler throws you error C2664 on 'DrawText' function call, you may replace it by 'DrawTextA'. In fact, all win32 API functions dealing with character strings can be added an 'A' to the end to avoid unicode cast errors.
  3. Visual C++ 2008 Express don't support C99 standard about int32_t, uint32_t. You have to add #include "nptypes.h" in top of plugin.h file. For xulrunner 1.9.0.1 SDK, npapi.h file uses int32, uint32 which is different from int32_t, uint32_t defined in nptypes.h, and it may cause problems in link stage.
  4. For xulrunner 1.9.0.1 SDK, you may not find npfunctions.h in include directories. You have to replace all npfunctions.h by npnpp.h in #include line.
  5. Feel free to append here your issues fixes if the above guide helped you.

Original Document Information

  • Author(s): Ben Bucksch
  • Copyright Information: ManyOne

{{ languages( { "pl": "Project:pl/Przyk\u0142ady/Informacja_o_oryginalnym_dokumencie", "ja": "Project:ja/Examples/Original_Document_Information" } ) }}

Revision Source

<h2 name="General_decisions">General decisions</h2>
<ul> <li>filename of DLL<br> must start with "np" (not "ns") and ends with ".dll" (I wasted hours on this - repeatedly)</li> <li>mimetype<br> reflects the data type handled by the plugin. this is how webpages invoke your plugin. should either be like "application/x-vnd-yourorganization-yourfiletype" or be officially registered with IANA (unlikely) or be a standard type (e.g. if you want to play MPEG files).</li> <li>file extension<br> reflects the data type handled by the plugin, esp. when loaded from local disk on Windows.</li>
</ul>
<h2 name="Build">Build</h2>
<ol> <li>Create a new project in Visual Studio for a <strong>Win32 GUI library</strong> (DLL) (in .NET 2003: <strong>Win32</strong> template, then switch to <strong>DLL</strong> in <strong>Application Settings</strong> in the following dialog, export symbols too?)(in Visual Studio 2008, it is <strong>Visualc++|Win32|Win32 Project</strong>, then check <strong>DLL</strong> in the wizard).</li> <li>If a wizard gives you a checkbox to create an <strong>empty project</strong>, then check it. Otherwise you'll delete files later.</li> <li>Again note that the resulting DLL filename must start with "<strong>np</strong>", so either call your project like this or rename the file later</li> <li>Delete the <strong>.cpp</strong> and <strong>.h</strong> and <strong>ReadMe</strong> files from the project and disk (if you did not create an empty project)</li> <li>Copy the npruntime sample plugin source code into the dir of the new VS project and add the files to the project using the VS GUI (<strong>.cpp</strong> files to "Source Files", <strong>.h</strong> files to "Header Files", <strong>.rc</strong> file to "Resource Files"). Samples can be obtained from: <a class="external" href="/en/Plugins/Samples_and_Test_Cases" title="https://developer.mozilla.org/en/Plugins/Samples_and_Test_Cases">https://developer.mozilla.org/en/Plugins/Samples_and_Test_Cases</a></li> <li>Download the <strong>Gecko SDK</strong> (aka XULRunner SDK) from mozilla.org release FTP and extract it. You can download it from here: <a class=" external" href="http://developer.mozilla.org/en/docs/Gecko_SDK" rel="freelink">http://developer.mozilla.org/en/docs/Gecko_SDK</a></li> <li>Add the <strong>Gecko SDK include path</strong> (example : C:\xulrunner-sdk\sdk\include) to <strong>Project Properties|(all configurations)|C++|General|Additional Include Directories</strong>. Note: If your project is still empty, the C++ tree might not be visible. So, add some files first.</li> <li>Add the following preprocessor definitions to <strong>Project Properties|(all configurations)|C++|Preprocessor|Preprocessor Definitions:</strong> <strong><code>WIN32;_WINDOWS;XP_WIN32;MOZILLA_STRICT_API;XPCOM_GLUE;XP_WIN;_X86_;NPSIMPLE_EXPORTS</code></strong></li> <li>Disable precompiled headers using <strong>Project Properties|(all configurations)|C++|Precompiled headers|Create/Use precompiled header</strong>. They may be already disabled.</li> <li>Define the function exports by adding the <strong>.def</strong> filename (e.g. nprt.def) to <strong>Project Properties|(all configurations)|Linker|Input|Module Definition File</strong>. It could be either the full path or the path relative to the project directory.</li> <li>Optional: Open the above <strong>.def</strong> file and change "NPRT" to the filename of your dll as VS sees it (without "np", if you decided to rename later)</li> <li>Optional: Edit the <strong>.rc</strong> file and and the top of <strong>npp_gate.cpp</strong> for the description, mimetype, file extension etc. to reflect your plugin</li> <li>Remove the function <strong><code>NPP_GetJavaClass</code></strong> from <strong>npp_gate.cpp</strong></li> <li>Build</li> <li>Rename the resulting DLL so that the filename starts with "<strong>np</strong>" and ends with ".dll" (or "32.dll"? 8.3?) and copy it in Mozilla's "plugins" folder</li> <li>Start Mozilla and open <strong>about:plugins</strong> to verify the plugin is detected</li> <li>Open the file "test.html" and begin testing. Make sure the mimetypes of your html embed tags match the mimetype specified in your <strong>nprt.rc</strong> file and the top of your <strong>npp_gate.cpp</strong> file</li>
</ol>
<h2 name="Version_Issues">Version Issues</h2>
<ol> <li>If you are using Gecko SDK v1.9 and higher, you'll probably need to add folders <strong>\plugin</strong>, <strong>\nspr</strong>, and <strong>\java</strong> as included directories (as seen above, go to <strong>Project Properties|(all configurations)|C++|General|Additional Include Directories</strong>). These directories are contained in the Gecko SDK include path that you previously added.</li> <li>If VC++ compiler throws you <strong><code>error C2664</code></strong> on 'DrawText' function call, you may replace it by 'DrawTextA'. In fact, all win32 API functions dealing with character strings can be added an 'A' to the end to avoid unicode cast errors.</li> <li>Visual C++ 2008 Express don't support C99 standard about <strong>int32_t</strong>, <strong>uint32_t</strong>. You have to add <strong>#include "nptypes.h"</strong> in top of <strong>plugin.h</strong> file. For <strong>xulrunner 1.9.0.1 SDK</strong>, npapi.h file uses <strong>int32</strong>, <strong>uint32 </strong>which is different from <strong>int32_t</strong>, <strong>uint32_t </strong>defined in <strong>nptypes.h</strong>, and it may cause problems in link stage.</li> <li>For <strong>xulrunner 1.9.0.1 SDK</strong>, you may not find <strong>npfunctions.h</strong> in include directories. You have to replace all <strong>npfunctions.h</strong> by<strong> npnpp.h</strong> in <strong>#include</strong> line.</li> <li>Feel free to append here your issues fixes if the above guide helped you.</li>
</ol>
<div class="originaldocinfo">
<h2 name="Original_Document_Information">Original Document Information</h2>
<ul> <li>Author(s): Ben Bucksch</li> <li>Copyright Information: ManyOne</li>
</ul>
</div>
<p>{{ languages( { "pl": "Project:pl/Przyk\u0142ady/Informacja_o_oryginalnym_dokumencie", "ja": "Project:ja/Examples/Original_Document_Information" } ) }}</p>
Revert to this revision