Ok so here's my code in my form:
Here's my callback function in my module:
My problem is that the SetWindowLong function ALWAYS FAILS! When run from the VB6 IDE, I keep getting error 1413. When run from a compiled EXE it generates error 0. As you can see from reading my code, this situation can only come about when there's no error, meaning that it has found that the original procedure pointer being found is zero. But using GetWindowLong instead of the return value from SetWindowLong, one quickly finds that the original procedure's pointer is NOT zero.
This leads me to believe that there's a bug in the API function itself.
Not sure if this has anything to do with it, but I'm using Windows 7 x64, rather than Windows XP x86. Is this API function SetWindowLong specifically designed to only work in Windows XP?
Code:
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetLastError Lib "kernel32.dll" () As Long
Private Declare Sub SetLastError Lib "kernel32.dll" (ByVal dwErrCode As Long)
Dim OriginalProcPtr As Long
Private Sub Form_Load()
SetLastError 0
OriginalProcPtr = SetWindowLong(Form1.hwnd, AddressOf MyWindowProc, -4)
If OriginalProcPtr = 0 Then
Print "ERROR "; CStr(GetLastError)
Else
Print OriginalProcPtr
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If OriginalProcPtr <> 0 Then SetWindowLong Form1.hwnd, OriginalProcPtr, -4
End Sub
Code:
Public Type WINDOWPOS
hwnd As Long
hWndInsertAfter As Long
x As Long
y As Long
cx As Long
cy As Long
flags As Long
End Type
Public Sub MyWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, lParam As WINDOWPOS)
Form1.Print hwnd
Form1.Print Msg
End Sub
This leads me to believe that there's a bug in the API function itself.
Not sure if this has anything to do with it, but I'm using Windows 7 x64, rather than Windows XP x86. Is this API function SetWindowLong specifically designed to only work in Windows XP?