3

我正在尝试使用 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();
4

1 回答 1

4

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

不,不幸的是它没有。Windows Mobile 不包括user32.dll以及许多其他普通的 Windows API DLL。相反,您通常需要 P/Invoke into 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();
于 2011-09-08T19:03:19.987 回答