ハンスの助けを借りてこれを整理したことは知っていますが、完全を期すために、を使用する代わりに、で装飾された明示的なインターフェイスをClassInterface(ClassInterfaceType.AutoDual)
使用して実装することをお勧めします。ClassInterface(ClassInterfaceType.None)
InterfaceType(ComInterfaceType.InterfaceIsDual)>
手間はかかりますが、インターフェイス GUID を完全に制御できます。AutoDual は、コンパイル時にインターフェイスの一意の GUID を自動生成します。これは時間の節約になりますが、それらを制御することはできません。
使用すると、これは次のようになります。
<ComVisible(True), _
Guid(Guids.IEmployeeGuid), _
InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IEmployee
<DispIdAttribute(1)> _
ReadOnly Property FirstName() As String
<DispIdAttribute(2)> _
ReadOnly Property LastName() As String
<DispIdAttribute(3)> _
Function EtcEtc(ByVal arg As String) As Boolean
End Interface
<ComVisible(True), _
Guid(Guids.EmployeeGuid), _
ClassInterface(ClassInterfaceType.None)> _
Public NotInheritable Class Employee
Implements IEmployee
Public ReadOnly Property FirstName() As String Implements IEmployee.FirstName
Get
Return "Santa"
End Get
End Function
'etc, etc
End Class
GUID の宣言方法に注意してください。GUID を統合し、Intellisense を提供するヘルパー クラスを作成するとうまくいくことがわかりました。
Friend Class Guids
Public Const AssemblyGuid As String = "BEFFC920-75D2-4e59-BE49-531EEAE35534"
Public Const IEmployeeGuid As String = "EF0FF26B-29EB-4d0a-A7E1-687370C58F3C"
Public Const EmployeeGuid As String = "DE01FFF0-F9CB-42a9-8EC3-4967B451DE40"
End Class
最後に、これらをアセンブリ レベルで使用します。
'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid(Guids.AssemblyGuid)>
'NOTE: The following attribute explicitly hides the classes, methods, etc in
' this assembly from being exported to a TypeLib. We can then explicitly
' expose just the ones we need to on a case-by-case basis.
<Assembly: ComVisible(False)>
<Assembly: ClassInterface(ClassInterfaceType.None)>