我試圖調用TrackPopupMenu
函數在運行時從託管的VB.NET代碼顯示菜單。 下面是我得到的錯誤:如何從託管的vb.net代碼調用TrackPopupMenu函數
PInvokeStackImbalance檢測消息: '!UeWIPopupX UeWIPopupX.mDeclares :: TrackPopupMenu' A調用的PInvoke功能 具有不平衡 堆棧。這很可能是因爲託管的PInvoke簽名 與非託管目標籤名不匹配。檢查呼叫 約定和PInvoke簽名的參數是否與目標 非託管簽名相匹配。
下面是我使用TrackPopupMenu函數聲明:
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True, CallingConvention:=CallingConvention.StdCall)> _
Friend Function TrackPopupMenu(ByVal hMenu As Long, ByVal wFlags As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nReserved As Integer, ByVal hWnd As IntPtr, ByVal lprc As RECT) As Integer
End Function
下面是調用TrackPopupMenu
函數的代碼:
dim lpRc as RECT
Dim tP As POINTAPI
Dim lR as Integer
Dim lUn as Integer
lUn = TPM_RIGHTBUTTON Or TPM_TOPALIGN Or TPM_LEFTALIGN Or TPM_RETURNCMD
tP.x = 50
tP.y = 100
'Here I am getting the error
lR = TrackPopupMenu(m_ppMenu.Tools(1).hMenu, lUn, tP.x, tP.y, 0, m_hWndOwner, lpRC)
下面是矩形RECT
聲明:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Structure RECT
Dim Left As Integer
Dim Top As Integer
Dim Right As Integer
Dim Bottom As Integer
End Structure
TrackPopupMenu調用期間的所有參數都有一些值。 我嘗試了不同的callingConvention,但仍然出現錯誤。
我無法解決這個問題。有誰知道如何解決這個問題?