C# COM entry point function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?R2Vvcmdl?=

    #1

    C# COM entry point function

    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
    DLLGetClassObje ct, but it seems C# does not need these functions?

    Here is a sample from MSDN.

    http://msdn2.microsoft.com/en-us/lib...38(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
  • Willy Denoyette [MVP]

    #2
    Re: C# COM entry point function

    "George" <George@discuss ions.microsoft. comwrote in message
    news:03377E5B-B2FD-4381-AAE8-97503A60D65A@mi crosoft.com...
    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
    DLLGetClassObje ct, but it seems C# does not need these functions?
    >
    Here is a sample from MSDN.
    >
    http://msdn2.microsoft.com/en-us/lib...38(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.


    Comment

    • =?Utf-8?B?R2Vvcmdl?=

      #3
      Re: C# COM entry point function

      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/lib...71(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 InterfaceImplem entation is in the reg file, but
      public interface IManagedInterfa ce 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

      "Willy Denoyette [MVP]" wrote:
      "George" <George@discuss ions.microsoft. comwrote in message
      news:03377E5B-B2FD-4381-AAE8-97503A60D65A@mi crosoft.com...
      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
      DLLGetClassObje ct, but it seems C# does not need these functions?

      Here is a sample from MSDN.

      http://msdn2.microsoft.com/en-us/lib...38(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.
      >
      >
      >

      Comment

      • Willy Denoyette [MVP]

        #4
        Re: C# COM entry point function

        "George" <George@discuss ions.microsoft. comwrote in message
        news:8BB02861-FF97-4136-812D-2ADE9F357CB5@mi crosoft.com...
        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/lib...71(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 InterfaceImplem entation is in the reg file, but
        public interface IManagedInterfa ce 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 CoCreateInstanc e, nor
        will it include the (optional) registration done by the custom registration
        functions (see ComRegisterFunc tionAttribute).

        Willy.

        Comment

        Working...