Question about registering COM server and Add Reference to it in a C# project
- by smwikipedia
I build a COM server in raw C++, here is the procedure:
(1) write an IDL file to define the interface and library.
(2) use msidl.exe to compile the IDL file to necessary .h, .c, .tlb files.
(3) implement the COM server in C++ and build a .dll file.
(4) add the following registry entris:
[HKEY_CLASSES_ROOT\RawComCarLib.ComCar.1\CurVer]
@="RawComCarLib.ComCar.1"
;CLSID
[HKEY_CLASSES_ROOT\CLSID{6CC26343-167B-4CF2-9EDF-99368A62E91C}]
@="RawComCarLib.ComCar.1"
[HKEY_CLASSES_ROOT\CLSID{6CC26343-167B-4CF2-9EDF-99368A62E91C}\InprocServer32]
@="D:\com\Project01.dll"
[HKEY_CLASSES_ROOT\CLSID{6CC26343-167B-4CF2-9EDF-99368A62E91C}\ProgID]
@="RawComCarLib.ComCar.1"
[HKEY_CLASSES_ROOT\CLSID{6CC26343-167B-4CF2-9EDF-99368A62E91C}\TypeLib] @="{E5C0EE8F-8806-4FE3-BC0E-3A56CFB38BEE}"
;TypeLib
[HKEY_CLASSES_ROOT\TypeLib{E5C0EE8F-8806-4FE3-BC0E-3A56CFB38BEE}]
[HKEY_CLASSES_ROOT\TypeLib{E5C0EE8F-8806-4FE3-BC0E-3A56CFB38BEE}\1.0]
@="Car Server Type Lib"
[HKEY_CLASSES_ROOT\TypeLib{E5C0EE8F-8806-4FE3-BC0E-3A56CFB38BEE}\1.0\0]
[HKEY_CLASSES_ROOT\TypeLib{E5C0EE8F-8806-4FE3-BC0E-3A56CFB38BEE}\1.0\0\win32]
@="D:\com\Project01.tlb"
[HKEY_CLASSES_ROOT\TypeLib{E5C0EE8F-8806-4FE3-BC0E-3A56CFB38BEE}\1.0\FLAGS]
@="0"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TypeLib{E5C0EE8F-8806-4FE3-BC0E-3A56CFB38BEE}\1.0\0\win32]
@="C:\Windows\System32\msdatsrc.tlb"
(5) I try to add reference to the COM by click the Add Reference in the C# project.
(6) In the COM tab, I saw my "Car Server Type Lib", it's ok until now.
I try to use the Object Browser to browse my COM lib, but the Visual Studio said "the following components could not be browsed", and I noticed that there's no new reference added to the list in the C# project Reference.
I can use the tlbimp.exe to generate a interop.CarCom.dll, and then use the COM through this interop dll, but I want this interop assembly to be generated automatically when I just add reference to the COM.
Could someone tell me what's wrong?
Many thanks.