2011-09-08 68 views
3

我試圖使用pInvoke,但在模擬器和設備上調用我是.NET新手(我是一名C++開發人員),我不明白JIT /框架如何找不到DLL /方法/等。我如何解決「System.MissingMethodException = {」在Windows 6.5上找不到PInvoke DLL'user32.dll'。「}?

有什麼我需要做的它的工作

在尋找類似的問題,看來我可能會或可能不會有添加DLL要麼溶液或CAB - ?但我在哪裏得到這個文件

肯定的操作系統。該設備有user3 2.DLL?而Windows 7版本不可能是正確的安裝在設備上的,可以嗎?

EDIT

的這些中的任何一個出現故障:

[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(); 
+0

你能提供PInovke簽名? – JaredPar

回答

4

當然該設備上的OS具有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(); 
+0

那麼我從哪裏得到它們呢? – Tim

+0

我看過你提供的鏈接 - 但簽名仍顯示user32.dll。我很困惑。 - http://pinvoke.net/default.aspx/coredll.SetWindowPos# – Tim

+0

我只是將名稱從user32更改爲coredll,它似乎工作。謝謝 – Tim

相關問題