Compiling The npruntime Sample Plugin in Visual Studio

这篇翻译不完整。请帮忙从英语翻译这篇文章

通用选项

  • DLL的文件名
    必须以 "np" (不是 "ns") 开头并且以 ".dll" 结尾(我在这个地方一次又一次的犯错,小心)
  • mimetype
    映射了这个插件处理的数据类型. 同时也是网页唤起你的插件的一个标识. 应该像是 "application/x-vnd-yourorganization-yourfiletype" 或者 在IANA上注册的类型 (不太可能)或者是一种标准类型(例如,如果你想要播放MPEG文件的话).
  • 文件扩展名
    映射了插件处理的数据类型,尤其是当插件从Windows系统的本地磁盘中加载的时候。

Build

  1. 创建一个Win32 GUI library工程 (DLL) (在.NET 2003版本中: 选择模板中的Win32 , 然后在弹出的对话框中找到应用程序类型,勾选DLL, 不添加公共头文件。)(在VS2008版本中,选择Visualc++|Win32|Win32 Project, 然后在向导中勾选DLL).
  2. 如果向导询问你是否创建一个空项目,那么勾选它。否则你需要在后面手动删除向导给你创建的文件。
  3. 请注意接下来的DLL创建中文件名必须以"np"开头, 你可以以这样的命名格式给你的工程命名,或者在后面的步骤中重命名你的项目。
  4. (如果你不是创建了一个空项目才需要进行此步骤)从你的工程与磁盘中删除.cpp文件、.h文件、ReadMe文件。
  5. 复制npruntime例子插件源码到新创建工程的VS目录下,然后使用VS的界面向导方式添加这些文件到工程中。(.cpp文件添加到"源文件", .h 文件添加到 "头文件", .rc 文件添加到"资源文件"). 例子可以从以下网址获取:
    https://developer.mozilla.org/en/Plugins/Samples_and_Test_Cases
  6. 下载NPAPI SDK.
  7. 添加NPAPI SDK的include目录 (例如 : C:\npapi-sdk\headers) 到项目属性|(所有配置)|C++|常规|附加包含目录. 注意: 如果你的项目仍然为空,C++树可能无法查看。所以先添加一些文件吧。
  8. Add the following preprocessor definitions to Project Properties|(all configurations)|C++|Preprocessor|Preprocessor Definitions: WIN32;_WINDOWS;XP_WIN32;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 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.
  2. 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.
  3. Feel free to append here your issues fixes if the above guide helped you.

文档标签和贡献者

此页面的贡献者: chrisdavidmills, Jeff-Kook
最后编辑者: Jeff-Kook,