在Visual Studio 2010中将Native / C ++ DLL链接到托管C ++ / CLI包装器

问题描述 投票:0回答:1

在我的visual studio解决方案中,我有一个包含本机C ++代码的dll,一个C ++ / CLI dll,我试图为我的非托管类型实现一个包装器,最后是我的C#应用​​程序。

我目前无法在我的包装器DLL中引用我的非托管类型。

代码片段:

// In the unmanged file (in the unmanged dll project)
using std::vector;
namespace populationwin32 
{
  class PopulationWin32
  {
  public:
    PopulationWin32();
  // ...
  };
}

// In the managed file. (in the manged dll project)
using namespace system;
using populationwin32::PopulationWin32;
namespace GSODFileParsing 
{
  public ref class PopulationWin32Wrapper
  {
  public:
    PopulationWin32Wrapper();
  private:
    PopulationWin32 *_populationWin32; // unmanaged object   
  }; // End class
} // End namespace

当我尝试编译托管dll(包含包装器)时,我收到以下错误:

Error   1   error C2653: 'populationwin32' : is not a class or namespace name
Error   2   error C2873: 'PopulationWin32' : symbol cannot be used in a using-declaration
Error   4   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   

任何想法这些错误是什么意思?我认为他们没有正确链接到无人管理的dll,但我不确定如何做到这一点,我在网上找到的所有东西都说不同。任何机构都知道如何正确和完整地链接一个无人管理库(DLL项目)与托管VC ++ / CLI包装器库(DLL项目)?

注意:这两个库都是单个visual studio解决方案中的项目。

编辑:感谢Olaf Dietsche的评论,我补充道

#include "PopulationWin32.h"

到包装头文件但现在我收到以下错误:

错误1错误C1083:无法打开包含文件:'PopulationWin32.h':没有这样的文件或目录

是否有我缺少的设置或我是否需要在两个DLL项目中包含头文件?顺便说一下,我通过properties-> configuration properties-> linker-> input-> Additional Dependencies将unmanged dll输出.lib文件添加为托管dll的依赖项。

c# visual-studio-2010 dll linker c++-cli
1个回答
1
投票

你的第一个错误'populationwin32' : is not a class or namespace name意味着,编译器不知道这个命名空间。

添加一个

#include "PopulationWin32.h"

使Visual Studio知道这个。

您还必须添加包含文件的路径,以便编译器可以找到它。这里描述的是VC++ Directories, Projects and Solutions, Options Dialog Box和这里的The #include Directive

© www.soinside.com 2019 - 2024. All rights reserved.