Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting an error from yesterday. The error is (PInvokeStackImbalance was detected
Message: A call to PInvoke function 'WebCam ScreenShot!WebCam_ScreenShot.Form1::SendMessage' 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). This are My codes :-
VB
Public Class Form1
   Private Sub OpenPreviewWindow()
        Dim iHeight As Integer = picCapture.Height
        Dim iWidth As Integer = picCapture.Width
        hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, picCapture.Handle.ToInt32, 0)
        If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
            SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
            SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
            SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
            SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCapture.Width, picCapture.Height, SWP_NOMOVE Or SWP_NOZORDER)
            btnSave.Enabled = True
            btnStop.Enabled = True

            btnStart.Enabled = False
        Else
            DestroyWindow(hHwnd)
            btnSave.Enabled = False
        End If
    End Sub


Please help in this. The underlined line is error showing in vb. Thanks on advance
Posted
Updated 10-Sep-14 20:33pm
v2

Quote:
... likely because the managed PInvoke signature does not match the unmanaged target signature ...
Check that the datatype of hHwnd is correct - it must be an IntPtr.
Also iDevice mut be an IntPtr.
And did you define WM_CAP_DRIVER_CONNECT as UInteger?
 
Share this answer
 
Comments
Bernhard Hiller 12-Sep-14 2:27am    
If you do not understand that, then the things you try are still beyond your capabilities. Sorry for these hard words, but they are true.
Member 10874152 15-Mar-15 6:02am    
i'have check this "Check that the datatype of hHwnd is correct - it must be an IntPtr.
Also iDevice mut be an IntPtr.
And did you define WM_CAP_DRIVER_CONNECT as UInteger?"

but it's don't work?

can you fix it ?
This is sometimes caused by using the wrong calling convention in the pinvoke declaration.
You don't show the declarations of your pinvoke methods, so this is a guess.

As I am not very good at VB I am not sure how this is declared in this language.
In c# you write like this.
C#
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention.StdCall)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

CallingConvention.StdCall is the default value.

See this link for more info: pinvoke.net: SendMessage (user32)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900