Click here to Skip to main content
15,900,725 members
Home / Discussions / COM
   

COM

 
GeneralRe: CoCreateInstance() returns the error saying "The specific module could not be found." Pin
urssmiling12-Jul-05 20:23
urssmiling12-Jul-05 20:23 
QuestionOne IDL, Multiple Implementations? Pin
Vertig011-Jul-05 11:21
Vertig011-Jul-05 11:21 
AnswerRe: One IDL, Multiple Implementations? Pin
Anonymous11-Jul-05 21:35
Anonymous11-Jul-05 21:35 
GeneralRe: One IDL, Multiple Implementations? Pin
Vertig012-Jul-05 7:48
Vertig012-Jul-05 7:48 
GeneralRe: One IDL, Multiple Implementations? Pin
Lim Bio Liong14-Jul-05 4:28
Lim Bio Liong14-Jul-05 4:28 
GeneralRe: One IDL, Multiple Implementations? Pin
Akth20-Jul-05 14:13
Akth20-Jul-05 14:13 
GeneralRe: One IDL, Multiple Implementations? Pin
Lim Bio Liong20-Jul-05 15:33
Lim Bio Liong20-Jul-05 15:33 
GeneralRe: One IDL, Multiple Implementations? Pin
Lim Bio Liong25-Jul-05 7:40
Lim Bio Liong25-Jul-05 7:40 
Hello Akth,

Thanks very much for the research and knowledge sharing. For the benefit of other readers, I'm summarizing our findings :

1. A COM interface defined in an IDL can be implemented by a .NET component. In order to implement the COM interface in a .NET language, C# say, the COM definitions contained in the IDL must be converted to compatible C# definitions.

This is achieved by creating a Primary Interop Assembly for the TYPE LIBRARY of the COM IDL and then referencing this PIA inside the C# project. The following are specific steps required for this :

1.1 First creating a strong name key (.snk) file. The PIA will need to be installed into the Global Assembly Cache (GAC). Hence, it needs to be signed. A .snk file is needed for the signing process. Use the sn.exe .NET utility to generate a .snk file. For example :

sn -k ObjectInterfaces.snk

1.2 Once a strong name key file is generated, we can proceed to create the PIA. This is achieved by using the tlbimp.exe .NET utility. Use the /keyfile option (to specify the .snk file we just created) and the /primary option to specify that we want to create a PIA. For example :

tlbimp ObjectInterfaces.tlb /sysarray /out:Interop.ObjectInterfaces.dll /keyfile:ObjectInterfaces.snk /primary

The above command line will generate a PIA with filename Interop.ObjectInterfaces.dll.

1.3 Now that the PIA is created, we will need to install the PIA into the Global Assembly Cache (GAC). This is accomplished by using the gacutil.exe .NET utility. For example :

gacutil -i Interop.ObjectInterfaces.dll



2. With a GAC-installed PIA in hand, we can now reference it inside our C# project. Use the Project|Add Reference menu to do this.

2.1 Once this is done, the various COM interface and other IDL definitions will be translated into C# types. You can see this inside the Object Browser.

2.2 You will now need to define a C# class that implements the intended COM interface. Let's say your C# class is Class1 and it is defined inside the CSharpImpl01 namespace. The resultant COM-interface C# implementation will have the progid "CSharpImpl01.Class1".



3. Once you have created your C# .NET component, CSharpImpl01.dll say, it cannot be used directly as a COM component in a COM client application. It is, after all, a .NET assembly consisting of BYTE CODES.

3.1 It can, however, be created and used by a COM client with the help of the Microsoft .NET Runtime Execution Engine (mscoree.dll). The resultant object will look and feel just like any ordinary COM object (to a client).

3.2 However, in actual fact, it remains a .NET component and what gets passed to the COM client is actually a proxy.

3.3 In order that mscoree.dll be able to load CSharpImpl01.dll and more specifically, the "COM object" with the progid "CSharpImpl01.Class1" on request, the usual COM information for it must first be registered.

3.4 This is done by using the regasm.exe .NET utility. For example :

regasm CSharpImpl01.dll /tlb

The /tlb option will make regasm generate a COM Type Library file for CSharpImpl01.dll. This type library file (i.e. CSharpImpl01.tlb) can be used by a COM client for import purposes.

3.5 Take note that regasm will generate a COM CLSID for "CSharpImpl01.Class1" and store the usual COM registration information plus some .NET specific information. If you look up the "InprocServer32" registry entry for the CLSID, you will note that the server is NOT CSharpImpl01.dll. It is mscoree.dll instead.

3.6 That's right, it is the .NET Runtime Execution Engine that serves as the COM server. It acts as the middle-layer between your COM client and the .NET assembly CSharpImpl01.dll.

3.7 Finally we will also need to install the CSharpImpl01.dll assembly into the Global Assembly Cache. This is done so that mscoree.dll can locate your assembly. This is done by using the gacutil.exe utility, for example :

gacutil -i CSharpImpl01.dll

3.8 Note also that because the C# project had made a reference to the PIA interop.objectinterfaces.dll, CSharpImpl01.dll will be dependent on it. This is also why we had earlier installed the PIA.



4. Your COM client can now either import the CSharpImpl01.tlb type library (in order to reference the C#-to-COM object CLSID) or it can use the "CSharpImpl01.Class1" progid to instantiate the new "COM object".



I certainly hope the above explanations will be helpful to all.



Best Regards,
Bio.







Generalconverting the type library to a .net assembly failed Pin
jwjanzen11-Jul-05 3:18
jwjanzen11-Jul-05 3:18 
Generalwriting com/shell extensions in masm Pin
salafii8-Jul-05 6:56
salafii8-Jul-05 6:56 
GeneralRe: writing com/shell extensions in masm Pin
Michael Dunn18-Jul-05 2:49
sitebuilderMichael Dunn18-Jul-05 2:49 
GeneralWhen Create Instance,Error in CoCreateInstanceEx Pin
stonewall_20007-Jul-05 21:57
stonewall_20007-Jul-05 21:57 
GeneralBuilding class in COM Pin
Logan from Singapore6-Jul-05 16:11
Logan from Singapore6-Jul-05 16:11 
GeneralThread profiling in C++/COM components Pin
rajandpayal6-Jul-05 15:51
rajandpayal6-Jul-05 15:51 
Questionaudio mux directshow filter? Pin
Taiwu Chiang6-Jul-05 11:38
Taiwu Chiang6-Jul-05 11:38 
Generalread input from a port Pin
kwena5-Jul-05 21:18
kwena5-Jul-05 21:18 
GeneralCreating an instance of a hidden interface Pin
Dave Moran5-Jul-05 9:51
Dave Moran5-Jul-05 9:51 
GeneralUsing Web Browser Pin
Chna5-Jul-05 0:25
Chna5-Jul-05 0:25 
GeneralSorry !! I occurs some problems when i add webservice to ATL COM Pin
clw89u4-Jul-05 16:21
clw89u4-Jul-05 16:21 
GeneralRe: Sorry !! I occurs some problems when i add webservice to ATL COM Pin
clw89u4-Jul-05 16:24
clw89u4-Jul-05 16:24 
GeneralCOM Newbie Question Pin
Steve Messer1-Jul-05 19:24
Steve Messer1-Jul-05 19:24 
GeneralRe: COM Newbie Question Pin
Christian Graus4-Jul-05 16:28
protectorChristian Graus4-Jul-05 16:28 
GeneralRe: COM Newbie Question Pin
Steve Messer4-Jul-05 19:41
Steve Messer4-Jul-05 19:41 
GeneralRe: COM Newbie Question Pin
Jörgen Sigvardsson5-Jul-05 12:40
Jörgen Sigvardsson5-Jul-05 12:40 
GeneralShell programming with COM Pin
alex__b30-Jun-05 19:13
professionalalex__b30-Jun-05 19:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.