使用c#管理的c++ dll。

时间:2022-09-01 17:09:49

I've created a dll using managed C++. Now I'm trying to use it from C#. I've added the Object to project references. Object browser shows the object in the dll correcly, path to the dll in object browser corresponds to the actual path.

我使用托管c++创建了一个dll。现在我试着从c#中使用它。我已经将对象添加到项目引用中。对象浏览器正确显示dll中的对象,对象浏览器中dll的路径对应实际路径。

However, when I run the C# program it complains:

然而,当我运行c#程序时,它会抱怨:

Unhandled Exception: System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

未处理的例外:先。无法找到指定的模块。(从HRESULT例外:0 x8007007e)

Any idea what else have to be done?

你知道还需要做什么吗?

Thanks.

谢谢。

4 个解决方案

#1


6  

I think that you're missing the other assemblies or dll's references by your managed C++ assembly.

我认为您的托管c++程序集丢失了其他程序集或dll的引用。

#2


0  

Does your managed C++ assembly have an other dependencies, including unmanaged dlls? You'll see this error at runtime if your referenced assembly fails to load a dependency.

托管c++程序集是否有其他依赖项,包括非托管dll ?如果引用的程序集未能加载依赖项,您将在运行时看到此错误。

#3


0  

Are you running the application in release on a machine without VS installed?

您是否在没有安装VS的机器上运行版本中的应用程序?

I only ask because I ran into a similar problem here: Mixed Mode Library and CRT Dependencies - HELP

我之所以问这个问题,是因为我遇到了一个类似的问题:混合模式库和CRT依赖——帮助

if you scroll down to my answer you can see what I did that helped me.

如果你向下滚动到我的答案,你会看到我所做的帮助了我。

#4


0  

Check that the c++ assembly is present in the same folder as your c# program. It should be copied over automatically if the 'Copy Local' property is set to true (on the reference to the c++ dll in your c# app).

检查c++程序集是否与c#程序在同一个文件夹中。如果'Copy Local'属性被设置为true(在c#应用程序中对c++ dll的引用中),则应该自动复制它。

If the c++ dll is there, the most likely problem is that the c++ dll depends on another non-managed dll which cannot be found (i.e. c# will not copy these to your app folder because it does not know about unmanaged references). You can use DependencyWalker on the c++ dll to check for missing dependencies.

如果c++ dll存在,最可能的问题是c++ dll依赖于另一个无法找到的非托管dll(例如,c#不会将它们复制到您的应用程序文件夹中,因为它不知道非托管引用)。您可以在c++ dll上使用DependencyWalker检查丢失的依赖项。

Another probable couse could be a problem with your MSVC runtime dlls. see if DependencyWalker complains about missing MSVCR*.dll, MSVCP*.dll etc... files.

另一个可能的问题可能是您的MSVC运行时dll的问题。看看家属是否抱怨错过了MSVCR*。dll,MSVCP *。dll等等……文件。

#1


6  

I think that you're missing the other assemblies or dll's references by your managed C++ assembly.

我认为您的托管c++程序集丢失了其他程序集或dll的引用。

#2


0  

Does your managed C++ assembly have an other dependencies, including unmanaged dlls? You'll see this error at runtime if your referenced assembly fails to load a dependency.

托管c++程序集是否有其他依赖项,包括非托管dll ?如果引用的程序集未能加载依赖项,您将在运行时看到此错误。

#3


0  

Are you running the application in release on a machine without VS installed?

您是否在没有安装VS的机器上运行版本中的应用程序?

I only ask because I ran into a similar problem here: Mixed Mode Library and CRT Dependencies - HELP

我之所以问这个问题,是因为我遇到了一个类似的问题:混合模式库和CRT依赖——帮助

if you scroll down to my answer you can see what I did that helped me.

如果你向下滚动到我的答案,你会看到我所做的帮助了我。

#4


0  

Check that the c++ assembly is present in the same folder as your c# program. It should be copied over automatically if the 'Copy Local' property is set to true (on the reference to the c++ dll in your c# app).

检查c++程序集是否与c#程序在同一个文件夹中。如果'Copy Local'属性被设置为true(在c#应用程序中对c++ dll的引用中),则应该自动复制它。

If the c++ dll is there, the most likely problem is that the c++ dll depends on another non-managed dll which cannot be found (i.e. c# will not copy these to your app folder because it does not know about unmanaged references). You can use DependencyWalker on the c++ dll to check for missing dependencies.

如果c++ dll存在,最可能的问题是c++ dll依赖于另一个无法找到的非托管dll(例如,c#不会将它们复制到您的应用程序文件夹中,因为它不知道非托管引用)。您可以在c++ dll上使用DependencyWalker检查丢失的依赖项。

Another probable couse could be a problem with your MSVC runtime dlls. see if DependencyWalker complains about missing MSVCR*.dll, MSVCP*.dll etc... files.

另一个可能的问题可能是您的MSVC运行时dll的问题。看看家属是否抱怨错过了MSVCR*。dll,MSVCP *。dll等等……文件。