VB 6 Com Interop question

B

Bryan Dickerson

I'm writing a DLL for which I want to expose a COM interface. I found the
check box on the Configuration to do that. So I built the solution, got
into my VB6 project, added the reference and started adding code, but there
was no intellisense, no properties, nothing. What did I do wrong?
 
J

Josip Habjan

Hi,

Set class ComClass attribute... and add ClassId, InterfaceId and EventsId
constant to your class.
In each class create new GUIDs for each of this three constants.

See sample below how i do it:

########################################################################
Option Explicit On
Option Strict On

Imports System.Text.Encoding
Imports System.Runtime.InteropServices

<ComClass(Helper.ClassId, Helper.EventsId, Helper.InterfaceId)> _
Public Class Helper

#Region " COM GUIDs "

Public Const ClassId As String = "6C1967B7-4EC8-4b70-BA94-C131EE892452"
Public Const InterfaceId As String =
"4CDC9471-D4E2-4824-BD4D-938EF299D58C"
Public Const EventsId As String = "4D18D7F1-BC51-49f0-824B-69F607EBD3B2"

#End Region

Sub New()
End Sub

Public Function UTF8BytesToString(ByVal buffer() As Byte) As String
If Not buffer Is Nothing Then
Return UTF8.GetString(buffer)
Else
Return String.Empty
End If
End Function

Public Function UTF8StringToBytes(ByVal text As String) As Byte()
Return UTF8.GetBytes(text)
End Function

End Class
########################################################################

I hope it helps.
 
B

Bryan Dickerson

How do I get the GUIDs?

Josip Habjan said:
Hi,

Set class ComClass attribute... and add ClassId, InterfaceId and EventsId
constant to your class.
In each class create new GUIDs for each of this three constants.

See sample below how i do it:

########################################################################
Option Explicit On
Option Strict On

Imports System.Text.Encoding
Imports System.Runtime.InteropServices

<ComClass(Helper.ClassId, Helper.EventsId, Helper.InterfaceId)> _
Public Class Helper

#Region " COM GUIDs "

Public Const ClassId As String = "6C1967B7-4EC8-4b70-BA94-C131EE892452"
Public Const InterfaceId As String =
"4CDC9471-D4E2-4824-BD4D-938EF299D58C"
Public Const EventsId As String =
"4D18D7F1-BC51-49f0-824B-69F607EBD3B2"

#End Region

Sub New()
End Sub

Public Function UTF8BytesToString(ByVal buffer() As Byte) As String
If Not buffer Is Nothing Then
Return UTF8.GetString(buffer)
Else
Return String.Empty
End If
End Function

Public Function UTF8StringToBytes(ByVal text As String) As Byte()
Return UTF8.GetBytes(text)
End Function

End Class
########################################################################

I hope it helps.
 
B

Bryan Dickerson

It works!! Now if I can just get the .Net part working correctly I'll be
flying!
Thanx!
 

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

Top