Windows Mobile 中找不到 PInvoke DLL 错误
我在获取在 Windows Mobile 5.0 模拟器上运行的基本方案时遇到了很多麻烦。我有一个 winforms 应用程序,最终会调用本机代码。部署工作正常,所有本机 DLL 都复制到与 winforms .exe 相同的文件夹中。我还使用远程文件查看器工具验证了这种情况。
然而,当我启动我的应用程序时,它总是失败,并出现“找不到 PInvoke dll -- System.MissingMethodException”错误(当调用本机代码时,DllImport 属性变得无用)。我知道本机 dll 与可执行文件位于同一文件夹中。我还应该做什么?
我用的是VS 2008。
I am having a lot of trouble getting a basic scenario to work on windows mobile 5.0 emulator. I have a winforms app that eventually calls into native code. Deployment works fine and all the native DLLs are copied in the same folder as the winforms .exe. I also verified this is the case with Remote File Viewer tool.
However when I launch my app, it always fails with "Can't find PInvoke dll -- System.MissingMethodException" error (when the time comes to call into native code, the DllImport attribute is rendered useless). I know that the native dll is found in the same folder as the executable. What more should I do?
I am using VS 2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了扩展 Jared 的答案,在 CF 中 P/Invoking 时出现 MissingMethodException 的四个更常见的原因:
您是否已验证 DLL 入口点未使用 dumpbin 之类的内容进行修饰?
To extend Jared's answer, four more common reasons to get a MissingMethodException while P/Invoking in the CF:
Have you verified the DLL entry points are undecorated with something like dumpbin?
根据错误消息,通常有以下两个问题之一:
__declspec(dllexport)
另外,健全性检查是为了确保 DLL 名称拼写正确且缺少.dll 后缀。
Given the error message there are usually one of 2 problems
__declspec(dllexport)
Also, sanity check is to make sure the DLL name is spelled correctly and lacking the .dll suffix.
你的问题是由于 WM5 内存管理很糟糕。 DLL 从插槽顶部到底部加载,而应用程序从底部到顶部加载。如果应用程序和 DLL 之间没有足够的空间,您将收到“无法 pinvoke”错误。
WM5 分配 32 个 32Mb 的插槽供应用程序运行。
每次 WM5 为 dll 分配内存时,它至少使用 64Kb 块,因此如果您的 DLL 是 32K,则需要 64k,如果您的 DLL 需要 68k,则 WM5 将分配 2x64Kb — 128Kb。
当WM5加载所需的DLL时,它总是加载到先前加载的应用程序的底部地址,即如果应用程序1加载了2×30kb DLL,则第一个将加载到地址0到64k,第二个加载到地址64到128 ,那么您的应用程序将从 128kb 开始加载其 DLL,而不是 0,即使您的应用程序运行到单独的插槽中。
为了使事情正常进行,您必须提前加载应用程序或从 Windows 启动文件夹中删除不需要的应用程序。
Your problem is due to the fact that WM5 memory managment is crap. DLLs are loaded from top of slot to bottom while apps are loaded from bottom to top. If you don't have enough space between your app and your DLL, you will receive a "can't pinvoke" error.
WM5 allocates 32 slots of 32Mb for applications to run into.
Each time WM5 allocates memory for dll, it uses a minimum of 64Kb block, so if your DLL is 32K, it will take 64k, if your DLL takes 68k then WM5 will allocate 2x64Kb — 128Kb.
When WM5 loads the DLL needed, it will always load at the bottom address of the previsouly loaded app, i.e. if app 1 has loaded 2×30kb DLLs, the first one will be loaded at address 0 to 64k, the second from 64 to 128, then your app will load its DLLs from 128kb, not 0, even if your apps runs into a separate slot.
In order to make things work, you will have to load your app earlier or remove non-needed apps from the windows starup folder.
您正在使用的 DLL 没有您所调用的方法的定义。
所以发生异常..
它编译得很好..仅在运行时出现问题..
解决方案是您需要确保该定义是否存在于 DLL 中,否则您需要寻找其他 dll。
The DLL what you are using doesn't have definition for the method what you are calling.
so the exception occurs..
it compiles fine.. only in run time problem occur..
solution is you need to make sure the definition is present in the DLL or not,else you need to go for some other dll.