Hi,
is it possible to pass a callback function from VB6 to VB.NET? I've tried
the following and got the error "Function pointer was not created by a
Delegate.".
______________________________
' VB.NET class library: Biblioteca.Class1
Imports System.Runtime.InteropServices
Imports System.Threading
Public Interface IClass1
Delegate Sub EndSomething_EventHandler()
Sub StartSomething(<MarshalAs(UnmanagedType.FunctionPtr)> ByVal
callbackFunction As IClass1.EndSomething_EventHandler)
End Interface
Public Class Class1
Implements IClass1
Public Sub StartSomething(ByVal callbackFunction As
IClass1.EndSomething_EventHandler) Implements IClass1.StartSomething
Thread.Sleep(5000)
If Not callbackFunction Is Nothing Then
callbackFunction.DynamicInvoke(Nothing)
Else
MsgBox("No callback function was received.", MsgBoxStyle.Critical)
End If
End Sub
End Class
______________________________
' V6 standard exe
' ---- Form1.frm ----
Option Explicit
Private Sub Command1_Click()
StartProcess
End Sub
' ---- Module1.bas ----
Option Explicit
Public Sub StartProcess()
Dim objVBNET As Biblioteca.IClass1
Set objVBNET = CreateObject("Biblioteca.Class1")
objVBNET.StartSomething AddressOf ShowMessage
End Sub
Public Sub ShowMessage()
MsgBox "This is the VB6 callback function.", vbExclamation
End Sub
Mattias Sj?gren - 26 Nov 2004 21:34 GMT
>is it possible to pass a callback function from VB6 to VB.NET?
Yes, but in current version of the CLR you will not be able to wrap a
delegate arnound it and call it that way, so it may not be very
useful. Whidbey will change that.
Mattias

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