簡體   English   中英

PostMessage導致“ ...對pinvoke函數的調用已使堆棧C#不平衡...”

[英]PostMessage results in “…a call to pinvoke function has unbalanced the stack c#…”

在32位托管應用程序中,我使用Proecess.Start加載64位.Net應用程序。 接下來,我使用MainWindowHandle將PostMessage()從32位應用程序發布到64位應用程序。 問題是,當調用PostMessage()時,出現錯誤“對PInvoke函數'xxxx :: PostMessage'的調用已使堆棧不平衡...”。按繼續后,一切正常。 我正在使用VS2017。如果我將32位應用程序轉換為64位,則沒有問題。 另外,在VS之外運行32位應用程序時,我也沒遇到問題。 這兩個應用程序都在C#中。 我可以僅取消MDA中的PInvokeStackImbalance還是應該“擔心”的事情?

謝謝

以下是表單中的代碼,用於啟動客戶端應用程序,停靠其主表單並將當前表單的句柄設置為客戶端應用程序。

    private const int SEND_HANDLE = WM_USER + 101;
    [DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)]
    private static extern bool PostMessage(IntPtr hwnd, uint Msg, long wParam, long lParam);
    private void DoDock()
    {
        ProcessStartInfo psi = new ProcessStartInfo("test.exe");
        psi.Arguments = "";
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = true;

        pDocked = Process.Start(psi);

        while (hWndDocked == IntPtr.Zero)
        {
            pDocked.WaitForInputIdle(1000);
            Thread.Sleep(100);
            pDocked.Refresh();
            if (pDocked.HasExited)                
                return;
            hWndDocked = pDocked.MainWindowHandle;  //cache the window handle
        }

        PostMessage(hWndDocked, SEND_HANDLE, this.Handle.ToInt32(), 0);
    }

這通常意味着您的拼字游戲聲明是錯誤的。 該網站列出了正確的聲明為:

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool PostMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM