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.InteropServicesConst
GW_CHILD = 5Dim
hwnd1 As Integerhwnd1 = 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 FunctionThis 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

API Call in VB 2005 Problem
Tommi Enenkel
The friendly Managed Debugger Assistants tell you that the GetWindow declaration is incorrect - the second parameter shouldn't be a Long (this is a 64bit value in Visual Basic .NET) - it should be an UInteger...
The P/Invoke site is an excellent source for P/Invoke signatures:
http://www.pinvoke.net/search.aspx search=GetWindow&namespace=[All]
For more info on MDA, see http://msdn2.microsoft.com/en-us/library/d21c150d(VS.80).aspx
Best regards,
Johan Stenberg