SetWindowLong in VB.NET
Posted on 2007-08-01
I recently attempted to make some conversions from VB6 to VB.NET and have run across a situation. Previously in VB6, my code was calling SetWindowLong with the following declaration:
Public Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
In trying to convert it to VB.NET, I was having to make calls to SetWindowLong and changing the WindowProc which required the 3rd parameter to use a delegate in VB.NET. Here is the signature that I ended up with.
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Form1.d_WindowProc) As Integer
Here is the delegate I ended up with
Public Delegate Function d_WindowProc(ByVal hWnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
And here is the call that I am making
lpPrevWndFunc = SetWindowLong(Me.Handle.ToInt32, GWL_WNDPROC, AddressOf WindowProc)
where WindowProc is a public function. So far so good except for the fact that later on in code (namely when the form is closed) the code trys to set the WindowProc back to what it was previously(which is stored in lpPrevWndFunc which is an Integer). But now I can't pass an integer to the SetWindowLong Function. How can I accomplish this??????