How to P/Invoke to a native dll from Metro?

别来无恙 提交于 2020-01-13 09:36:26

问题


I've got a library consisting of two parts - One .net assembly that P/Invokes to a native 3rd party dll. In desktop mode this works just fine: However, when referencing the assembly from a Metro style app and running it, it throws a System.DllNotFoundException on the P/Invoke complaining that "Unable to load DLL 'library': The specified module could not be found."

The native dll does not do anything special but only creates out-going TCP/IP connections to a server. The system cannot know this, but rather the native dll could do anything. This is why I suspect it might not be possible to do this.

Some dll search order is mentioned on msdn regarding Metro style apps, hinting about it is possible to load native dlls?

Also I found this link on msdn talking about loading "libraries" and mentions the PackageDependency in the manifest file, but to me it's still unclear how to add a native dll to the package in a way that it is possible to P/Invoke it.


回答1:


Add it to your project (right click project, Add, Existing Item.) Check that in the properties of that item, Content is set to True (it is false by default.) Build.




回答2:


This is probably by design. Your problem might be caused by an error with error code 126 being returned from LoadLibrary. If your application runs in desktop mode you should target desktop mode for your application. You might use an earlier version of Windows as well.



来源:https://stackoverflow.com/questions/7807361/how-to-p-invoke-to-a-native-dll-from-metro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!