COM Interop -- check my code please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Serge M. Ignatkin

    #1

    COM Interop -- check my code please

    Hello,

    after a lot of readings I've got something working. Can you please check --
    is it enough? .Net server and COM-client, also I generated key file and
    place "ref" to it in AssemblyInfo.vb this way:

    <Assembly: AssemblyKeyFile ("..\..\keyfile .snk")>

    The code:

    Namespace NSClientSource

    <ComVisible(Fal se)Public Delegate Sub DisconnectDeleg ate()

    <GuidAttribute( "4CD0B63A-5A3E-48d1-9E92-5C58B04909F1"), _
    InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIDispatch )_
    Public Interface ISClientEvents
    Sub Disconnect()
    End Interface

    <GuidAttribute( "F597E3DB-1BEB-4d41-8C3F-1CAA0AA6F659"), _
    InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIDispatch )_
    Public Interface ISClientMembers
    Property Port() As Integer
    Property Host() As String
    End Interface

    <ComSourceInter faces(GetType(I SClientEvents)) , _
    ComDefaultInter face(GetType(IS ClientMembers)) , _
    Guid("3964C432-8412-4c73-A04D-86D7C57D694E")_
    Public Class SClient
    Implements ISClientMembers
    Public Event Disconnect As DisconnectDeleg ate

    Public Enum EFaultReason
    eFaultUnknown = 0
    eFaultWrongLeng th = 1
    ...
    End Enum

    ....




    After all this I can use one (but not all) object in VB(A) application.
    All members and events are "visible", exept that enum members are shown in a
    bit strange way:

    EFaultReason_eF aultUnknown
    EFaultReason_eF aultWrongLength

    and so on -- with prefix, is it OK, or there's a way to make it shown
    without prefix?

    The third one in my project is a Control -- is it possible to use it also?
    Like ActiveX controls in old times?

    Although it's visible in COM object browser (F2 in MSA) but there's no way
    to place control in a form and use it. What should I read?

    Without <ComVisible(Fal se)DisconnectDe legate sub also shown in COM
    client -- but I don't need it?



    Thank you.

    --
    best regards!

  • Mattias Sjögren

    #2
    Re: COM Interop -- check my code please

    Serge,
    >All members and events are "visible", exept that enum members are shown in a
    >bit strange way:
    >
    >EFaultReason_e FaultUnknown
    >EFaultReason_e FaultWrongLengt h
    >
    >and so on -- with prefix, is it OK, or there's a way to make it shown
    >without prefix?
    Yes it's ok, and there's not much you can do about it.

    >The third one in my project is a Control -- is it possible to use it also?
    >Like ActiveX controls in old times?
    No, hosting Windows Forms controls as ActiveX controls is generally
    not supported (with a few exceptions).

    >Without <ComVisible(Fal se)DisconnectDe legate sub also shown in COM
    >client -- but I don't need it?
    You don't have to expose the delegate class if that's what your
    asking.


    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    Working...