C# COM entry point function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello everyone,


I am a developer from C++ COM to C# COM. I feel confused about the entry
point function for a C# COM object.

In C++, we always initialize object through GetClassObject or
DLLGetClassObject, but it seems C# does not need these functions?

Here is a sample from MSDN.

http://msdn2.microsoft.com/en-us/library/aa645738(VS.71).aspx

So, in C# do we need to implement the required functions like
GetClassObject? If no need, which function is the entry point for C# COM
object -- I want to find the entry point function so that I can verify that
my C# COM object can begin to talk with other COM clients.


thanks in advance,
George
 
George said:
Hello everyone,


I am a developer from C++ COM to C# COM. I feel confused about the entry
point function for a C# COM object.

In C++, we always initialize object through GetClassObject or
DLLGetClassObject, but it seems C# does not need these functions?

Here is a sample from MSDN.

http://msdn2.microsoft.com/en-us/library/aa645738(VS.71).aspx

So, in C# do we need to implement the required functions like
GetClassObject? If no need, which function is the entry point for C# COM
object -- I want to find the entry point function so that I can verify
that
my C# COM object can begin to talk with other COM clients.


thanks in advance,
George


You don't (can't) have to expose the COM activation/deactivation entry
points, this is taken care of by mscoree.dll, who is registered as the
"real" COM server when you register a .NET assembly as COM server (using
regasm.exe for instance). mscoree.dll takes care of loading the CLR whenever
you create an instance of a .NET class from a native COM client, the CLR
takes care of loading the .NET assembly and exposing the core COM interfaces
(IUnknow) and the interfaces you declared in your code.

Willy.
 
Thanks Willy,


I have made some practices using regasm and following your comments. C# COM
development is really defferent from C++ development from entry point.

I am using MSDN sample COM server,

http://msdn2.microsoft.com/en-us/library/t9yw5271(VS.80).aspx

Then regasm will generate the following statements,

Code:
REGEDIT4

[HKEY_CLASSES_ROOT\CSharpServer.InterfaceImplementation]
@="CSharpServer.InterfaceImplementation"

[HKEY_CLASSES_ROOT\CSharpServer.InterfaceImplementation\CLSID]
@="{C6659361-1625-4746-931C-36014B146679}"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}]
@="CSharpServer.InterfaceImplementation"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="CSharpServer.InterfaceImplementation"
"Assembly"="CSharpServer, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\InprocServer32\0.0.0.0]
"Class"="CSharpServer.InterfaceImplementation"
"Assembly"="CSharpServer, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\ProgId]
@="CSharpServer.InterfaceImplementation"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\Implemented
Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]

I find only public class InterfaceImplementation is in the reg file, but
public interface IManagedInterface is not in reg file. I do not know why
regasm only cares about public classes -- why interface is not in reg file?

(I think for client, the interface may also be used in application?)


regards,
George
 
George said:
Thanks Willy,


I have made some practices using regasm and following your comments. C#
COM
development is really defferent from C++ development from entry point.

I am using MSDN sample COM server,

http://msdn2.microsoft.com/en-us/library/t9yw5271(VS.80).aspx

Then regasm will generate the following statements,

Code:
REGEDIT4

[HKEY_CLASSES_ROOT\CSharpServer.InterfaceImplementation]
@="CSharpServer.InterfaceImplementation"

[HKEY_CLASSES_ROOT\CSharpServer.InterfaceImplementation\CLSID]
@="{C6659361-1625-4746-931C-36014B146679}"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}]
@="CSharpServer.InterfaceImplementation"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="CSharpServer.InterfaceImplementation"
"Assembly"="CSharpServer, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\InprocServer32\0.0.0.0]
"Class"="CSharpServer.InterfaceImplementation"
"Assembly"="CSharpServer, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\ProgId]
@="CSharpServer.InterfaceImplementation"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\Implemented
Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]

I find only public class InterfaceImplementation is in the reg file, but
public interface IManagedInterface is not in reg file. I do not know why
regasm only cares about public classes -- why interface is not in reg
file?

(I think for client, the interface may also be used in application?)


regards,
George

The /reg option is meant for informational purposes only, you should
register your classes with the /tlb option. Classes that are registered
using the reg file won't be able to be created using CoCreateInstance, nor
will it include the (optional) registration done by the custom registration
functions (see ComRegisterFunctionAttribute).

Willy.
 
Hi Willy,


I am confused about your reply. /tlb option is just generating a type
library from the specified assembly containing definitions of the accessible
types defined within the assembly. TLB file is used for client to make build.

Why do you say TLB file is used for registering COM classes into Windows
Registery? In Regasm document, we just run regasm <DLL name> to register into
Windows registry.


regards,
George

Willy Denoyette said:
George said:
Thanks Willy,


I have made some practices using regasm and following your comments. C#
COM
development is really defferent from C++ development from entry point.

I am using MSDN sample COM server,

http://msdn2.microsoft.com/en-us/library/t9yw5271(VS.80).aspx

Then regasm will generate the following statements,

Code:
REGEDIT4

[HKEY_CLASSES_ROOT\CSharpServer.InterfaceImplementation]
@="CSharpServer.InterfaceImplementation"

[HKEY_CLASSES_ROOT\CSharpServer.InterfaceImplementation\CLSID]
@="{C6659361-1625-4746-931C-36014B146679}"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}]
@="CSharpServer.InterfaceImplementation"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="CSharpServer.InterfaceImplementation"
"Assembly"="CSharpServer, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\InprocServer32\0.0.0.0]
"Class"="CSharpServer.InterfaceImplementation"
"Assembly"="CSharpServer, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\ProgId]
@="CSharpServer.InterfaceImplementation"

[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\Implemented
Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]

I find only public class InterfaceImplementation is in the reg file, but
public interface IManagedInterface is not in reg file. I do not know why
regasm only cares about public classes -- why interface is not in reg
file?

(I think for client, the interface may also be used in application?)


regards,
George

The /reg option is meant for informational purposes only, you should
register your classes with the /tlb option. Classes that are registered
using the reg file won't be able to be created using CoCreateInstance, nor
will it include the (optional) registration done by the custom registration
functions (see ComRegisterFunctionAttribute).

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top