When you create a project for Visual studio there are a couple of key steps that are highlighted here from the original guild from Mozilla “Compiling The npruntime Sample Plugin in Visual Studio”
From the build steps listed in the article from Mozilla,
- Create a new project in Visual Studio. Make sure that you create a generic Win32 Project.
- In the application setting, select a DLL project and make sure to check the “empty Project” check-box.
- Steps 4& 5 – If you have created an empty project, you will not have to delete any files. Add the npruntime source files that you download from Mozilla.
- steps 6 & 7 – You will need the xulrunner SDK to build the project. After downloading and installing the SDK you will need to point the include paths to build the NPAPI plugin.
- step 8 you will need to add the correct preprocessor defines to build properly.
- step 9 – if you have created an empty project, the pre-compiler headers should be disabled.
- An omitted step is the addition of the library paths for the linker to find the xulrunner-sdk libraries.
- step 10 – add the module definition file to the project. This is important to export the proper NPAPI functions needed to load the plugin in the browser.
that should be enough to build the control at this point. From here you would want to continue with the Mozilla link to configure the plugin MIME type string so you can define your own data type for the control to use.
If you try to build the project at this point, it will fail with errors. As the Mozilla and Gecko SDK’s have evolved, this sample has not been kept up to date which is disappointing.
To fix the problems you will need to do the following:
- The control should be compiled with UNICODE enabled. Otherwise older browsers such as Firefox will not properly load the plugin if the absolute path to the plugin contains spaces.
- Visual Studio does not properly handle the C99 standards about the int32_t and other C99 types. You will have to manually update the code to get around this issue. Change integer types (int16, int32, uint16, uint32) to use the new modern prototypes (int16_t, int32_t, uint16_t, and uint32_t). As Gecko evolved, the data types changed. The sample code was never updated and won’t compile without these changes.
- change headers. The old header “npupp.h” has been replaced by “npfunctions.h”. Mozilla – Bug 455458 covers the change to these headers. This was done back in 2008 with Gecko 2.0 (Firefox 4).
- fix property setter method. There is a bug with the sample code when you process a property and set a value.
- debugging with Firefox: attach the debugger to the app “plugin_container.exe” and this will let you debug your code within visual studio. Be careful! if you take too long, Firefox will think the plugin crashed and kill the app and end your session.
- Debugging with Chrome: This is a lot like debugging with IE. Chrome launches a new Chrome process to contain the plugin, so you need to figure out which process belongs to the plugin and attach the debugger to that process. Typically this is the Chrome process with the highest process ID as reported by Visual Studio.
If you get to this point, you should have a Visual studio project that you can build.
Hey, I just stopped by to visit your website and thought I’d say thank you.
i am happy to find this post very useful for me, as it contains lot of information. i always prefer to read the quality content and this thing i found in your post. thanks for sharing lista de email lista de email lista de email lista de email lista de email
Thanks for the post! Did you manage to print the output to Visual Studio’s console ?
No, the console that I typically used was provided by the debug version of FireFox.
Too bad, I can’t find any information about the console. I’m going to output messages to a text file. Thx for your time!
To print to the debug window in Visual Studio, you use the OutputDebugString() function. If you are attempting to interact with the console window, you can think of it as a specialized console session, more like stderr and less like stdcon.
It just worked, thx !
You should add this info to your post.
but that’s the cool part, we just did 🙂
Just a couple of notes on OutputDebugString(). If you call this function in release mode, it will continue to print to the debug console. The ATLTRACE() macros wrap this function so you only use it in debug mode. That’s what the ATL and MFC debug trace macros are all about.
Pingback: Visual Studio project settings for NPAPI projects | conedogers
Its showing error in JRIENV and jref in the following lines of code
JRIEnv* NPN_GetJavaEnv(void)
{
JRIEnv *rv = NULL;
rv = NPNFuncs.getJavaEnv();
return rv;
}
jref NPN_GetJavaPeer(NPP instance)
{
jref rv;
rv = NPNFuncs.getJavaPeer(instance);
return rv;
}
How to resolve it
My solution was not to support Java. To many recent security issues. You can try a older release of the xulrunner SDK. I do not recall if the newer SDK’s support java.
google chrome/ firefox unable to load my plugin.
Google along with Firefox are slowly deprecating NPAPI support from the browsers. I was working with a company in late 2013 and we could not get our NPAPI controls to load either.
http://blog.chromium.org/2013/09/saying-goodbye-to-our-old-friend-npapi.html
I suspect that Google has either accelerated their shutdown of NPAPI, or because this sample code is unsigned, chrome is not loading the unsigned control. Either way, NPAPI’s days are numbered.
http://www.chromium.org/developers/npapi-deprecation
Pingback: Visual Studio project settings for NPAPI projects | conedogers
Pingback: Visual Studio project settings for NPAPI projects | Conedogers