pinvoke 失败,因为 DLL 依赖于其他 SXS-DLL
简而言之,问题是:当 A.dll 依赖于另一个 SXS-lib(在我的例子中是 MSVCR90.DLL)时,如何使用 p/invoke 从 DLL A.dll 调用函数?
我想使用 pinvoke 调用 DLL 中的函数。 pinvoke 本身对于其他库工作得很好。从非托管 C++ 调用 DLL 中的函数也可以正常工作。
问题在于该 DLL 引用了位于某些 SXS 文件夹中的 MSVCR90.DLL。
在 C++ 中使用 LoadLibrary 可以按照提到的方式使用该库。使用 C# 我不知道如何加载库。我总是收到一条错误消息,指出计算机上缺少 MSVCR90.DLL。
这就是加载库的样子:
[DllImport("C:\\work\\dllhell\\sample\\sample.dll",
EntryPoint = "sample", CallingConvention = CallingConvention.Cdecl)]
public static extern int sample();
当调用函数sample
时,我只收到以下错误:HRESULT:0x8007007E,表示找不到该库。实际上,该库以各种版本存在于 SXS 目录中。
我尝试使用 Dependency Walker (取决于),但到目前为止它还无法找到正确版本的库。
该库还附带一个包含以下条目的清单:
清单中包含以下语句:
<assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8'
processorArchi tecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
我的计算机上存在请求的版本,我使用的是 VS 2010,它提供了该库的较新版本,但不应该我想是个问题。
我发现很多帖子都在讨论类似的问题。我知道,我有依赖性问题,但我无处找到解决方案。我知道我缺少的依赖项,我有一个清单,但这也应该适用于 C# 吗?不仅适用于非托管 C++?
Problem in short: How to call a function from DLL A.dll using p/invoke when A.dll depends on another SXS-lib (in my case MSVCR90.DLL)?
I'd like to call a function within a DLL using pinvoke. pinvoke itself works fine for other libs. Calling the function in the DLL from unmanaged C++ works fine, too.
The problem is that the DLL has a reference to MSVCR90.DLL which resides in some SXS folders.
Using LoadLibrary in C++ the library can be used as mentioned. Using C# I don't know how to get the library loaded. I always get an error that MSVCR90.DLL was missing on the computer.
This is what loading the library looks like:
[DllImport("C:\\work\\dllhell\\sample\\sample.dll",
EntryPoint = "sample", CallingConvention = CallingConvention.Cdecl)]
public static extern int sample();
When calling the function sample
, I only get the following error: HRESULT: 0x8007007E saying that the library would not have been found. Actually, the library exists in various versions in SXS directories.
I tried using Dependency Walker (depends) but it also has not been able to locate the right version of the library, so far.
There is also a manifest shipped with the library containing the following entry:
The following statement is included within the manifest:
<assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8'
processorArchi tecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
The version requested exists on my machine, I'm using VS 2010 which ships newer versions of that library but that shouldn't be a problem, I guess.
I found a lot of threads discussing similar problems. I know, I have a dependency issue but I could nowhere find a solution. I know my missing dependency, I have a manifest but should that do it for C#, too? Not only for unmanaged C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人搜索该问题:当然,David Heffernan 已经解决了该问题,必须将依赖项添加到应用程序的清单中,即文件 app.manifest,如果没有此类文件,请将其创建为项目中的新清单, 然而。
以下条目就足够了:
该条目直接转到 XML 文件中的根节点程序集。
感谢大卫·赫弗南(David Heffernan),忘记我最后的评论,它已经解决了我的问题。
In case anyone searches for that issue: of course, David Heffernan has solved the issue, the dependency has to be added to the application's manifest, i.e. the file app.manifest, create it as new manifest in your projekt if there is no such file, yet.
The following entry is sufficient:
This entry goes directly to the root node assembly in the XML file.
Thanks to David Heffernan, forget about my last comment, it has been the solution to my question.