简体   繁体   English

在C#项目中添加C ++ dll的引用时出现问题

[英]Problem adding reference of C++ dll in C# project

I implemented a C++ dll that compiled successfully. 我实现了一个成功编译的C ++ dll。 The project contains a header and cpp file. 该项目包含一个头文件和cpp文件。 The cpp file includes several third party headers (Cplex mainly). cpp文件包含几个第三方头(主要是Cplex)。

Once the dll was created: I then attempted to reference the dll in visual studio and it didn't work. 创建dll后:我随后尝试在Visual Studio中引用该dll,但该目录不起作用。 In the console application, I used the tlbimp.exe and I encountered the error message: 在控制台应用程序中,我使用了tlbimp.exe,并且遇到了错误消息:

<AssemblyFileName.dll> is not a valid type library.

I then used dependency walker and it showed the error message: 然后,我使用了依赖项遍历器,并显示了错误消息:

"MSVCR90.DLL was not found".

I am surely missing something and would appreciate if you can point what the solution could be? 我肯定会错过一些东西,如果您能指出解决方案是什么,我将不胜感激。

If you donot have Visual Studio 2008 you will get the error MSVCR90.dll. 如果您没有Visual Studio 2008,则会收到错误MSVCR90.dll。 You can just install the Visual Studio 2008 runtime and then you will not have any dependecy errors related to MSVCR90. 您只需安装Visual Studio 2008运行时,就不会出现与MSVCR90相关的任何错误。

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en http://www.microsoft.com/downloads/zh-CN/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en

There are two issues here, one is that not all native dlls are also type libraries, only COM ones. 这里有两个问题,一个是不是所有的本机dll都是类型库,只有COM的。

the second error is more like you do not have a Visual C++ runtime available, are you building the C++ dll on the same box of trying to use it? 第二个错误更像是您没有可用的Visual C ++运行时,您是否在尝试使用C ++ dll的同一盒子上进行构建?

for non COMN dlls, instead of import the type library you could use DLLImport approach. 对于非COMN dll,可以导入DLLImport方法,而不是导入类型库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM