Building Firefox Plugins using Visual Studio

by APIJunkie 22. September 2008 00:59

If you are in the business of writing components/plugins that work inside browsers and even if your target audience is Windows users, you can't ignore Firefox anymore.

IE is still the most popular browser by far but Firefox is a force to reckon with when it comes to writing browser plugins.

If you use Visual studio as a development environment and want to develop plugins for Firefox here are a few points to get you started.

First checkout the article OpenGL sample as Firefox plugin on code project. It is a great and simple example on how to write a Firefox plugin.

Second, because some things have changed since the above article was written, follow the steps below to get the Firefox plugin project to work on Visual Studio:

1. Download the Firefox source code version you want

    Example: the Firefox 3.0.1 version is found here

2. Extract to yourroot\mozilla

   Example C:\Projects\XProj\mozila

3. Download the Gecko SDK/ XULRunner SDK source code version you want

    Example: the Gecko 1.9 (Firefox 3.0) version is found here

4. Extract to yourroot\xulrunner-sdk(for Firefox version 3.0) or yourroot\gecko-sdk(for Firefox version 1.5-2.0)

   Example C:\Projects\XProj\xulrunner-sdk

5. Run unix2dos on npbasic.dsp and npbasic.dsw (you can find them at yourroot\mozilla\modules\plugin\tools\sdk\samples\basic\windows)

6. Open the npbasic Visual Studio project (you can find it at yourroot\mozilla\modules\plugin\tools\sdk\samples\basic\windows)

7. Inside Visual Studio go to project properties and set the additional include directories:

For Firefox 1.5-2 (gecko-sdk) change to->

yourroot\gecko-sdk\include; yourroot\mozilla\modules\plugin\tools\sdk\samples\include

For Firefox 3 (xulrunner-sdk) change to ->

yourroot\xulrunner-sdk\sdk\include; yourroot\mozilla\modules\plugin\tools\sdk\samples\include

8. Fix a compilation bug in npplat.h:

When building the project you might receive the following error:

error C2146: syntax error : missing ';' before
identifier 'ContextRecord'

The error can be fixed by changing the order of some of the include files inside npplat.h.

The following 2 include lines are found in npplat.h:

#include "npapi.h"

#include "npupp.h"

You will need to move them from the beginning of the npplat.h to a place beyond where the Windows include files are included.

For Example if the original file looks like this:

...

#ifndef _NPPLAT_H_

#define _NPPLAT_H_

#include "npapi.h"

#include "npupp.h"

/**************************************************/

/* Windows */

/**************************************************/

#ifdef XP_WIN

#include "windows.h"

#endif //XP_WIN

...

The modified file should look like this:

...

#ifndef _NPPLAT_H_

#define _NPPLAT_H_

/**************************************************/

/* Windows */

/**************************************************/

#ifdef XP_WIN

#include "windows.h"

#endif //XP_WIN

#include "npapi.h"

#include "npupp.h"

.....

 9. Rebuild the project.

10. You should be good to go now. Good luck!

 

Tags:

C++ | How To | Firefox

Comments

9/22/2008 1:54:36 AM #

trackback

Trackback from DotNetKicks.com

Building Firefox Plugins using Visual Studio

DotNetKicks.com

9/22/2008 8:47:31 PM #

asp.net

thx, great srticle, so simple and easy Smile

asp.net Russia

9/23/2008 6:24:02 AM #

pingback

Pingback from alvinashcraft.com

Dew Drop - September 23, 2008 | Alvin Ashcraft's Morning Dew

alvinashcraft.com

9/24/2008 2:10:37 AM #

Jeff Klawiter

Another interesting possibility is to host the CLR within the plugin (ala SilverLight). Most of the work would be in using Mono for Linux and Mac OS X and the full framework on Windows (or could use Mono all around).

Jeff Klawiter United States

9/25/2008 3:24:06 AM #

NinjaCross

Thankyou so much for this interesting article, I was searching for something like this !

NinjaCross Italy

9/27/2008 11:38:03 AM #

pingback

Pingback from weblogs.asp.net

Interesting Finds: 2008.09.22~2008.09.27 - gOODiDEA.NET

weblogs.asp.net

11/27/2008 1:19:23 AM #

varsha

Hi,

   I checked your article "Building Firefox Plugins using Visual Studio".
I followed all steps you had given in this article. But I cann't open project i.e. (.dsw) in VC++6.0.

I also tried to create using VS2005 win32|dll.(for Firefox 3.0)  Then I got the following error
"Error  1  error LNK2019: unresolved external symbol _NPN_UserAgent referenced in function "public: char const * __thiscall nsPluginInstance::getVersion(void)" (?getVersion@nsPluginInstance@@QAEPBDXZ)"

I attached my project zip file with this mail.

Please provide me build sample of this "npBasic" project for windows platform.
I want know the visual studio type to build the plugin.

If you have build copy of this project then please provide me.


Thanks & Regards
Varsha

varsha India

11/28/2008 1:22:51 AM #

APIJunkie

Hi Varsha,

Since VS 2005 offers many improvements over VS 6, you should open the project with Visual Studio 2005(VS 2008 should also work fine although I haven't tried it yet).
When you first open the project in VS 2005 it will detect that the project was created using an older version and ask you to convert it to a newer version.
Tell VS to convert the project and remember to follow all the steps I talked about in the post.
Also note that the error you received probably has to do with the fact that you tried to recreate the project manually instead of letting VS convert it and preserve correct the settings.

Good luck!

  JB

APIJunkie United States

1/4/2009 11:04:30 PM #

pingback

Pingback from bytes.com

how to make plugins - bytes

bytes.com

Comments are closed

About the author

Name of author

I was first wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

  James Bacon