RE: vb.net Automation Issues - COM Interop
- From: rmacias <rmacias@xxxxxxxxxxxxxxxx>
- Date: Thu, 13 Apr 2006 08:34:02 -0700
You have to make your classes visible to COM. Try the following code. Of
course, make sure you change the GUIDs by using the GUID generator utility.
Imports System.Runtime.InteropServices
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch), _
Guid("A42C5454-6324-4be2-A7FE-A2868AE055DC")> _
Public Interface _ClientInterface
<DispId(1)> Sub Invoke()
<DispId(2)> Function GetSomeString() As String
End Interface
<ClassInterface(ClassInterfaceType.None), _
ProgId("CommsClass.ClientInterface"), _
Guid("1B6D1711-FD8A-4b34-A806-06B5EE45962E")> _
Public Class ClientInterface
Implements _ClientInterface
Public Function GetSomeString() As String Implements
_ClientInterface.GetSomeString
Return "Hello World From .NET"
End Function
Public Sub Invoke() Implements _ClientInterface.Invoke
MessageBox.Show("Message Box Invoked in .NET", ".NET Message Box",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
"SiJP" wrote:
I've been having a few issues recently in creating a vb.net class.
library (using vs.net 2003), registering it for com interop and then
invoking its functions from an object in VB6.
The error I am receiving is happening in VB6 when I go to compile the
project:
Compile Error:
Function or Interface marked as restricted, or the function uses an
Automation type not supported in Visual Basic
Here is my vb6 code, which is run from a button on a test form:
Private Sub cmdInvoke_Click()
On Error GoTo err_handler
Dim obj As CommsClass.ClientInterface
Set obj = New CommsClass.ClientInterface
obj.Invoke
Exit Sub
err_handler:
MsgBox Err & " - " & Error
End Sub
And here is my vb.net CommsClass code. This is the ONLY code I have in
the project, and the project is registered for COM Interop.
Public Class ClientInterface
Public Function Invoke() As String
MsgBox("Hi")
End Function
End Class
Why would somthing so simply cause such an awkward error?!
Thanks
- Follow-Ups:
- Re: vb.net Automation Issues - COM Interop
- From: SiJP
- Re: vb.net Automation Issues - COM Interop
- References:
- vb.net Automation Issues - COM Interop
- From: SiJP
- vb.net Automation Issues - COM Interop
- Prev by Date: Re: Title Bar is visible
- Next by Date: Re: Duplicate controls on tab pages
- Previous by thread: vb.net Automation Issues - COM Interop
- Next by thread: Re: vb.net Automation Issues - COM Interop
- Index(es):