[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern IntPtr FindWindowEx(IntPtr ph, IntPtr ch, String cn, String wn);
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, long nCmdShow);
private void button1_Click(object sender, System.EventArgs e)
{
try
{
IntPtr handle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
ShowWindow(handle, 0);//运行到这里会报异常```而任务栏正确隐藏了``` }
catch { }
}
它报的异常:检测到 PInvokeStackImabalance对 PInvoke 函数“WindowsApplication2!WindowsApplication2.Form1::ShowWindow”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。请各位高手帮忙看下。。
先谢了。。
public static extern IntPtr FindWindowEx(IntPtr ph, IntPtr ch, String cn, String wn);
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, long nCmdShow);
private void button1_Click(object sender, System.EventArgs e)
{
try
{
IntPtr handle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
ShowWindow(handle, 0);//运行到这里会报异常```而任务栏正确隐藏了``` }
catch { }
}
它报的异常:检测到 PInvokeStackImabalance对 PInvoke 函数“WindowsApplication2!WindowsApplication2.Form1::ShowWindow”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。请各位高手帮忙看下。。
先谢了。。
改成
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
请教一下。。
在此long 跟 int 有什么区别?
还是我方法的声明本身就有错误??
而某些语言中,int是16位,long是32位的,所以用你那种写法