MozNET Tutorial - Native XPCOM Component
I'm not going to delve very deep into the subject of native XPCom components because, well.. The main component we're talking about here is written in a managed lanaguage and that's what most of us develop with. But, since it is fully possible to use custom, native, components I will at least provide you with a basic project that you can use either as a template to create your own component or just something to screw around with.Crack Open VC++
Compiling a native component is not as straight-forward as we would like and I'm no C/C++ guru so I'm not going to try to explain how to set anything up. I will, however, tell you that if you develop primarily (or only) with Visual Studio 2010 you're going to need to install VC++ 2008 (the Express edition won't work for this!). Native components need to target the VC9 runtime and VS 2010 can't target that runtime without VS 2008 being installed.A Component Skeleton
Yeah, I know. Stupid. But, that's how Microsoft does things.
Let's get started...
Now you need a base, something to start building your plugin from. Below you'll find a link to a skeletal component that you can use as a template for building your own XPCOM addon.
Native Component Source Project
As for how to define and access your component from your application.. That's pretty easy too. Define (redefine in this case) your interface as a managed version, inside your application (do it just like you would if you were extending MozNET), now create an instance of your interface just like any other interface: eg.
nsIMyInterface myInterfaceInstance = XPCom.CreateInstance<nsIMyInterface>("@mysite.com/my-component;1");
Now you can use the
to call on properties and methods of your component.
If someone wants to pick up the ball and run with this, be my guest. If you come up with a better tutorial for everyone I'll replace this one with yours.