Building Firefox Plugins using Visual Studio

by APIJunkie 9/22/2008 12:59:00 AM

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!

 

Currently rated 4.3 by 3 people

  • Currently 4.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

C++ | How To | Firefox

Fix for the DataGrid does not exist in the namespace error in Silverlight 2 beta 2

by APIJunkie 6/10/2008 7:27:00 AM

When upgrading an existing Silverlight project to silverlight 2 beta 2 you might encounter the following error:

"The type or namespace name 'DataGrid' does not exist in the namespace 'System.Windows.Controls' (are you missing an assembly reference?)"

To solve the problem:

1. First go to your project references (Expand your project references sub tree in the Visual Studio IDE) and  look for System.Windows.Controls.Data in the reference list.

(If it does not exist in the list then you probably had the problem before the upgrade and you need to add a reference to System.Windows.Controls.Data by going to Project/Add Reference/.Net and choosing it from the list)

2. Press the right button on the System.Windows.Controls.Data reference and choose properties.

3. If the "Specific Version" property is set to true, change the "Specific Version" property to False.

4. Rebuild the project/solution.

This solved the problem for us on several Silverlight projects using a DataGrid.

Cheers

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | PRB | Troubleshoot | How To

Getting around Silverlight 2 beta 1 error 4002 while changing visibility of a control on mouse click event

by APIJunkie 5/27/2008 11:27:00 PM

While working on  Bumble Beegger we came across a daunting problem that only seemed to happen under certain conditions.

Silverlight error message
ErrorCode: 4002
ErrorType: ManagedRuntimeError
Message: System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component.
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at System.Windows.DependencyObject.MethodEx(String methodName, CValue[] cvData)
at System.Windows.UIElement.ReleaseMouseCapture()
at System.Windows.Controls.Primitives.ButtonBase.ReleaseMouseCaptureInternal()
at System.Windows.Controls.Primitives.ButtonBase.OnLostFocus(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnLostFocus(Object sender, RoutedEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) 

After a few hours of debugging, experimenting and googling I came across a discussion on Silverlight.net that shed some light on the problem.

As it turns out there is bug in Silverlight 2 beta 1 that can cause a crash when changing the visibility of a button control inside a mouse event handler.

The recommended workarounds around this problem were to change the size to 0,0 or change the opacity to 1.

Another option is to use the Canvas.ZIndexProperty and set it to a number that is smaller then your foreground elements.

The problem is that those does not always produce a similar enough effect in other elements.

If you still want to use visibility where possible, you can check the type of control and choose to modify visibility, size, opacity or Z Index according to the type.

Granted this is a horrible hack but it gets the job done until we can get our hands on beta 2...

Example:

// assume uiElement points to some valid UIElement

UIElement uiElement;

// check element type, if its not a button set visibility to collapsed else use ZIndex for a similar effect

if (uiElement.GetType() != typeof(Button)) 

   uiElement.Visibility = Visibility.Collapsed;

else

   ((Button)uiElement).SetValue(Canvas.ZIndexProperty, -1);

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | PRB | How To | Debug

Cannot access localhost on Vista when debugging local ASP.NET Applications

by APIJunkie 5/6/2008 5:31:00 PM

If you are trying to debug ASP.NET applications on Vista you might run into the following problem:

localhost is not accessible through your browser and the error that is displayed is "Internet Explorer cannot display the webpage".

After some googling I ran across a reference to the same problem.

The problem has to do with the fact that there are 2 entries for local host in the hosts file ([Windows directory]\System32\drivers\etc\hosts).

One for ipv4 and one for ipv6.

Example:

127.0.0.1 localhost
::1 localhost

To solve the problem you can remark one of them. The example below remarks the ipv6 entry.

127.0.0.1 localhost
# Causes problems when using localhost ->
#::1 localhost

Note that you might not be able to modify the hosts file even if you are running as an administrator.

The following Microsoft KB explains how to change the hosts file:

http://support.microsoft.com/default.aspx?scid=kb;en-us;923947

Hope this helps...
 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET | PRB | Vista | How To | Debug

How to configure sourcesafe for internet access

by APIJunkie 5/2/2008 7:17:00 AM

I was looking for a good source on setting up sourcesafe access over HTTP/HTTPS.

Unfortunately MSDN help on this subject is a little scarce.

I found this great guide for setting up sourcesafe over an internet connection

It is a very detailed step by step guide that can get you up and running very fast.

Kudos to Alin Constantin for the great guide :)

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

IIS | How To | sourcesafe

How to fix the server method failed Maximum length exceeded error when using ASP.NET AJAX

by APIJunkie 3/14/2008 1:21:00 AM

If you are using ASP.NET AJAX to create RIA's (Rich Internet Applications) you might run into the maximum length exceeded error.

This error occurs when you are trying to send too much data using ASP.NET AJAX from the client to the server and vice versa.

On the function call stack level this error occurs at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize or at System.Web.Script.Services.RestHandler.InvokeMethod depending if you are sending or receiving data.

The problem is that the default maximum size (102400 characters) does not suffice when you try to transfer a significant amount of data.

To increase the maximum allowed send/receive data you need to change the MaxJsonLength Property.

To change the MaxJsonLength Property you can edit your web.config file.

Look for the following commented section in the web.config file:

 

<!--
Uncomment this line to customize maxJsonLength and add a custom converter -->

<!--

<jsonSerialization maxJsonLength="500">

<converters>

<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>

</converters>

</jsonSerialization>

-->

 

Convert it to something along the following lines (see note below):

 

<!--
Uncomment this line to customize maxJsonLength and add a custom converter -->

<jsonSerialization maxJsonLength="200000"><

converters>

<!--<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>--></

converters>

</jsonSerialization>

 

Note that in the example above the max size was set to 200,000 characters.

You should calculate and test the size you will need for your data (there might be a few bytes of overhead so take that into account).

 

Currently rated 3.6 by 14 people

  • Currently 3.571429/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | AJAX | PRB | JSON | How To

How to get a base URL from a given URL in ASP.NET

by APIJunkie 2/23/2008 10:22:00 AM

Sometimes it is useful to get the base URL of a given URL.

For some reason there is no built in function in the URI class to do that.

A simple implementation of a function to get the base URL from a given URI would be:

////////////////////////////////////////////////////////////////

// Extract a base URL from a URL

////////////////////////////////////////////////////////////////

public Uri extractBaseURLFromURL(Uri url)

{

 
return new Uri(url.Scheme.ToString() + "://" + url.Authority);

}

////////////////////////////////////////////////////////////////

As a usage example if we call extractBaseURLFromURL and supply the following URL

http://msdn2.microsoft.com/en-us/netframework/default.aspx

The function will return the following URL 

http://msdn2.microsoft.com

----------

 Update:

----------

Nick Berardi offered a more elegant solution by using the GetLeftPart function (see discussion below):

Example:

// extract a base url from a url

public static Uri extractBaseURLFromURL(Uri url)

{

 
return new Uri(url.GetLeftPart(UriPartial.Authority));

}

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET | How To | Web Development

How to easily redirect from http to https in ASP.NET

by APIJunkie 2/23/2008 9:58:00 AM

Below is a simple code snippet to redirect from a non secure HTTP URL to a secure HTTPS URL using C# and ASP.NET.

The code checks if we are using a secure connection and if not it redirects to the same requested URL changing the protocol from HTTP to HTTPS.

////////////////////////////////////////////////////////////////

// Check if we are using https and if not redirect

///////////////////////////////////////////////////////////////

if(!Request.IsSecureConnection)

{

 
string redirectUrl = Request.Url.ToString().Replace("http:", "https:");

  Response.Redirect(redirectUrl);

}

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET | How To | Web Development

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author

My name is Bacon…James Bacon.

I am an API wars veteran I was wounded by x86 assembly, recovered and moved on to C. I am currently stuck in C++ and sniffing .NET.

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.

E-mail me Send mail


Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in