Why I can't create COM object in .NET but can in JavaScript

0

I can create an ActiveX in JS (html is opend by IE):

var o = new ActiveXObject("MyProgId");

But I can't create its instance in .NET:

var t = Type.GetTypeFromProgId("MyProgId");

returns null. When I try to add "reference to COM" in VS I get such error:

"Could not add a reference to {MyTypeLib_CLSID}\1.0
Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))"

When I search the registry for MyTypeLib_CLSID I do find the key but regedit can't open it under HKCR\Wow6432Node\TypeLib. It complains Error Opening Key, The system cannot find the file specified. But then I search next and regedit finds it under HKCU\Software\Classes\TypeLib and opens successfully there.

I also tried to create an object via Type.GetTypeFromCLSID with the same result (returns null).

What can be wrong with this COM?

P.S. This COM is Lync Web App Plugin ("ReachAppShAx.AppSharing"/{B89F72B4-7801-4F45-97AE-F9A0CDBB6213})

UPDATE: all these things happen locally: js/html is being opened in browser as a html-file, .net is a console app.

javascript
.net
com
activex
asked on Stack Overflow Apr 14, 2011 by Shrike • edited Apr 14, 2011 by Shrike

2 Answers

0

It's quite simple to achieve this task using Visual Studio. (Instructions are for Visual Studio 2005)

  1. Open a toolbox (View -> ToolBox)
  2. Right-click on the toolbox -> Choose Items
  3. Choose "COM Components" tab.
  4. Select COM components of your interest.

References are added to the project automatically as well.

Now you can simply drag'n'drop your COM components since CCW (COM Callable Wrapper) should be created automatically by Visual Studio.

answered on Stack Overflow Apr 14, 2011 by Pranay Rana • edited Apr 14, 2011 by Albireo
0

It seems I understand why I can't create CCW in .net for this COM - it's because this COM is out-of-process COM server. So JavaScript/IE can work with out-of-process COMs seamlessly but not C#.

So the question turns to "How to deal with Out-of-process COM in .NET/C#".

I've created wrapper with help of tlbimp.exe: tlbimp.exe CommunicatorWebAppVersion.exe

This creates me dll CwaAsVersionLib.dll which I add into my C# project. And then create instance as:

var o = new CwaAsVersionLib.CwaAsVersionQuery();

But! It works only if COM server is running. If it's running then creating instance fails with error: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

answered on Stack Overflow Apr 14, 2011 by Shrike • edited Apr 14, 2011 by Shrike

User contributions licensed under CC BY-SA 3.0