COM Interop -- check my code please

  • Thread starter Thread starter Serge M. Ignatkin
  • Start date Start date
S

Serge M. Ignatkin

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(False)> Public Delegate Sub DisconnectDelegate()

<GuidAttribute("4CD0B63A-5A3E-48d1-9E92-5C58B04909F1"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface ISClientEvents
Sub Disconnect()
End Interface

<GuidAttribute("F597E3DB-1BEB-4d41-8C3F-1CAA0AA6F659"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface ISClientMembers
Property Port() As Integer
Property Host() As String
End Interface

<ComSourceInterfaces(GetType(ISClientEvents)), _
ComDefaultInterface(GetType(ISClientMembers)), _
Guid("3964C432-8412-4c73-A04D-86D7C57D694E")> _
Public Class SClient
Implements ISClientMembers
Public Event Disconnect As DisconnectDelegate

Public Enum EFaultReason
eFaultUnknown = 0
eFaultWrongLength = 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_eFaultUnknown
EFaultReason_eFaultWrongLength

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(False)> DisconnectDelegate sub also shown in COM
client -- but I don't need it?



Thank you.
 
Serge,
All members and events are "visible", exept that enum members are shown in a
bit strange way:

EFaultReason_eFaultUnknown
EFaultReason_eFaultWrongLength

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(False)> DisconnectDelegate 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
 
Back
Top