检测到PInvokeStackImbalance [英] PInvokeStackImbalance was detected
问题描述
我昨天收到错误。错误是(检测到PInvokeStackImbalance
消息:调用PInvoke函数'WebCam ScreenShot!WebCam_ScreenShot.Form1 :: SendMessage'使堆栈失衡。这很可能是因为托管PInvoke签名不匹配非托管目标签名。检查PInvoke签名的调用约定和参数是否与目标非托管签名匹配)。这是我的代码: -
公共 类 Form1
私有 Sub OpenPreviewWindow()
Dim iHeight As 整数 = picCapture.Height
Dim iWidth As 整数 = picCapture.Width
hHwnd = capCreateCaptureWindowA(iDevice,WS_VISIBLE 或 WS_CHILD, 0 , 0 , 640 , 480 ,picCapture.Handle.ToInt32, 0 )
如果 SendMessage(hHwnd,WM_CAP_DRIVER_CONNECT,iDevice,< span class =c ode-digit> 0 )然后
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。宽度,picCapture.Height,SWP_NOMOVE 或 SWP_NOZORDER)
btnSave.Enabled = True
btnStop.Enabled = True
btnStart.Enabled = False
其他
DestroyWindow(hHwnd)
btnSave.Enabled = False
结束 如果
结束 Sub
请帮忙。带下划线的行是在vb中显示的错误。感谢提前
引用:...可能是因为托管PInvoke签名与非托管目标签名不匹配...
检查
hHwnd
的数据类型是否正确 - 它必须是IntPtr
。
另外iDevice
mut是IntPtr
。
And你有没有定义WM_CAP_DRIVER_CONNECT
作为UInteger
?
这有时是由于使用pinvoke声明中的错误调用约定。
你没有显示你的pinvoke方法的声明,所以这是猜测。
由于我不擅长VB,我不确定这是用这种语言声明的。
在c#中你这样写。
[DllImport( user32.dll,CharSet = CharSet.Auto, CallingConvention。 StdCall )]
静态 extern IntPtr SendMessage( IntPtr hWnd, UInt32 消息, IntPtr wParam, IntPtr lParam);
CallingConvention.StdCall
是默认值。
有关详细信息,请参阅此链接: pinvoke.net:SendMessage( user32) [ ^ ]
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 :-
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
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 anIntPtr
.
AlsoiDevice
mut be anIntPtr
.
And did you defineWM_CAP_DRIVER_CONNECT
asUInteger
?
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.
[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)[^]
这篇关于检测到PInvokeStackImbalance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!