Groups | Blog | Home
all groups > vb.net upgrade > june 2003 >

vb.net upgrade : Adding a delegate to fix "AddressOf" bug after upgrade


vince
6/30/2003 1:35:14 PM
New to delegates, trying to figure out how to use a
delegate to fix a bug after upgrading code from VB6 to
VB.NET using the Upgrade wizard...

I have the following callback proc:

Public Function BrowseCallBackProc(ByVal hwnd As
Integer, ByVal uMsg As Integer, ByVal lParam As Integer,
ByRef lpData As Integer) As Integer

I created the following delegate for it:

Public Delegate Function BrowseProcedureDelegate
(ByVal hwnd As Integer, ByVal uMsg As Integer, ByVal
lParam As Integer, ByRef lpData As Integer) As Integer

The bug occurs on this line later in the code:

.lpfnCallback = FnPtrToLong(AddressOf
BrowseCallBackProc)

I followed the link that the upgrade wizard gave for
fixing this type of bug, but have not been able to fix
the bug...

How can I use a delegate to give FnPtrToLong() a method
name...???

thanks very much
Christian_Fröschlin
7/1/2003 9:44:00 AM
[quoted text, click to view]

If a native method expects a function pointer as parameter,
you can declare this parameter as a delegate in the declaration
of the native method. .NET will then do some magic for you to
marshal this as function pointer, see

ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconusingcallbackfunctions.htm

In your case, it seems that the function pointer is
inside a struct. I don't know how to handle this case,
maybe custom marshalling is required.




Christian_Fröschlin
7/1/2003 1:54:44 PM
[quoted text, click to view]

Actually, I recently saw a statement that it should work

[quoted text, click to view]

http://www.dotnet247.com/247reference/msgs/28/144669.aspx


Try if you can simply declare the lpfnCallback as Delegate,
and use it like

Delegate Sub myMethodDelegate(...) 'Use callback signature here

....

..lpfnCallback = New myMethodDelegate(AddressOf BrowseCallBackProc)
AddThis Social Bookmark Button