Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2004

Tip: Looking for answers? Try searching our database.

Function pointer was not created by a Delegate.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GB - 26 Nov 2004 20:59 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.