Using .NET Components from Vista Sidebar Gadgets
Sometimes, when developing a non-trivial gadget, you need the full power of good old .NET. Fear not, with just a little bit of tasty COM Interop, .NET components can be successfully used from a gadget.
STEP 1 - Create your .NET component
[ComVisible(true)] public interface IMyComponent { void DoStuff(); } [Guid("31267db9-1912-4524-a757-4224b70d0282")] [ProgId("Mindscape.MyComponent")] [ClassInterface(ClassInterfaceType.None)] [ComVisible(true)] public sealed class MyComponent : IMyComponent { void DoStuff() { // yep, doing stuff... } }
STEP 2 - Register your .NET component
First, ensure your assembly is signed.
Either:
- Run regasm.exe <My.DotNet.dll> /codebase. Or,
- Or check “Register for COM Interop” in the Project Properties/Build tab. Or,
- Include gadget code to self-register the component. More to come on this…
STEP 3 - Consume your component from the gadget
Either:
Create your component using new ActiveXObject:
var myComponent = new ActiveXObject("Mindscape.MyComponent"); myComponent.DoStuff();
Create your component using the object tag. This seems to be required to have the gadget handle events from the component. More to come on this.
<object id="myComponent" classid="clsid:31267db9-1912-4524-a757-4224b70d0282"></object>
In upcoming posts I plan to cover in a bit more detail event handling and component self-registration.
Hope this helps.


