0

I'm trying to get the WNDPROC from a open Windows Explorer window. I can successfully get the handle of the window, but "GetWindowLongPtr" returns always "0".

I'm declaring the entry:

  <DllImport("user32.dll", EntryPoint:="GetWindowLongPtrW")> _
  Public Shared Function GetWindowLongPtrW(ByVal hWnd As HandleRef, <MarshalAs(UnmanagedType.I8)> ByVal nIndex As Long) As IntPtr

End Function

And I'm trying to get WNDPROC:

Dim ist As IntPtr
    Dim mtm As IntPtr
    Try

        ist = FindWindow("CabinetWClass", vbNullString)
        Dim ist2 As New HandleRef(0, ist)
        MsgBox(ist)
        mtm = GetWindowLongPtrW(ist2, 1)
        MsgBox(mtm)


    Catch ex As Exception
        MsgBox("Erro :(" & vbCrLf & vbCrLf & ex.ToString)
    End Try

But, the WNDPROC MSGBOX always returns 0... What I'm doing wrong?

demongolem
  • 9,474
  • 36
  • 90
  • 105
Meyer
  • 1
  • The GetWindowLongPtrW declaration is wrong, the second argument is an Integer. And you are using it wrong, you must pass -4 to get the WNDPROC value. And you forgot SetLastError so you also cannot get an error code that tells you what you are doing wrong. Use pinvoke.net to get good pinvoke declarations. – Hans Passant Feb 05 '13 at 18:32
  • @Hans Passant I added the "SetLastError" to declaration, and it's returning "0" too. The command "Marshal.GetLastWin32Error" is returning "0" after trying to get WNDPROC. Is the error in this part: "Dim ist2 As New HandleRef(0, ist)"? – Meyer Feb 05 '13 at 20:45

0 Answers0