如何修复“System.MissingMethodException = {”在Windows 6.5上找不到PInvoke DLL'user32.dll'。“}?

时间:2011-09-08 18:56:04

标签: c# .net windows-mobile-6.5

我正在尝试使用pInvoke,但是在模拟器和设备上,调用都失败了。我是.NET的新手(我是一名C ++开发人员),我不明白JIT /框架如何找不到DLL /方法/等。

我还需要做些什么才能让它发挥作用吗?

在查看类似的问题时,似乎我可能需要或不必将DLL添加到解决方案或CAB中 - 但是我从哪里获取该文件。

设备上的操作系统肯定有user32.dll吗?并且Windows 7版本可能不是在设备上安装的正确版本,可以吗?

修改

其中任何一个都失败了:

[DllImport("coredll.dll", EntryPoint = "FindWindowW", SetLastError = true)]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", SetLastError=true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

        [DllImport("user32.dll", SetLastError = true)]
        internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

        [DllImport("coredll.dll", EntryPoint = "SipShowIM")]
        public static extern bool SipShowIMP(int code);

        [DllImport("user32.dll")]
        public static extern IntPtr GetForegroundWindow();

1 个答案:

答案 0 :(得分:4)

  

设备上的操作系统肯定有user32.dll吗?

不,不幸的是没有。 Windows Mobile不包含user32.dll以及许多其他常规Windows API DLL。相反,您通常需要将P / Invoke转换为coredll.dll。有关签名,请参阅PInvoke.net的“智能设备功能”部分(左下角)。


编辑:

正如你在评论中提到的那样,那里的一些签名显然是不正确的。您可以查看Windows Mobile API以获取正确的签名功能(例如SetWindowPos)。

我相信,对你而言,大多数应该在coredll.dll

[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("coredll.dll", SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

[DllImport("coredll.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

[DllImport("coredll.dll", EntryPoint = "SipShowIM")]
public static extern bool SipShowIMP(int code);

[DllImport("coredll.dll")]
public static extern IntPtr GetForegroundWindow();