API Call in VB 2005 Problem

I am trying to make the following API call that worked in VB 2003 in VB 2005 and I am receiving the following error:

PInvokeStackImbalance was detected
Message: A call to PInvoke function 'GetWindowData!GetWindowData.GetWindowData::GetWindow' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

The GetDesktopWindow works fine returning 65556. The error occurs with GetWindow.

Imports System.Runtime.InteropServices

Const GW_CHILD = 5

Dim hwnd1 As Integer

hwnd1 = GetDesktopWindow()

hwnd1 = GetWindow(hwnd1, GW_CHILD)

<System.Runtime.InteropServices.DllImport("User32.dll", EntryPoint:="GetWindow", SetLastError:=True)> _

Private Shared Function GetWindow(ByVal hwnd As Integer, ByVal uCmd As Long) As Integer

End Function

This worked perfect in VB 2003. I have also tried changing Const GW_CHILD as long=5 and

using the followng declare instead of DLLImport

Public Declare Function GetWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Integer, ByVal uCmd As Long) As Integer

Any help would be greatly appreciated.

Marc



Answer this question

API Call in VB 2005 Problem