简体   繁体   中英

Linking Native/C++ DLL to Managed C++/CLI Wrapper in Visual Studio 2010

In my visual studio solution I have a dll containing native C++ code, a C++/CLI dll where I am trying to implement a wrapper for my unmanaged types, and finally my C# application.

I am currently unable to reference my unmanaged types in my wrapper dll.

Code Snippet:

// 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

When I try to compile the managed dll (containing the wrapper) I get the following errors:

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   

Any ideas what these errors mean? I'm thinking they are from not correctly linking to the unmanged dll, but I'm not sure how to do this and everything I find online says something different. Any body know how to correctly and completely link an unmanged library (dll project) with a managed VC++/CLI wrapper library (dll project)?

Note: Both these libraries are projects in a single visual studio solution.

Edit: Thanks to Olaf Dietsche's comments I added

#include "PopulationWin32.h"

To the wrapper header file but now I get the following error:

Error 1 error C1083: Cannot open include file: 'PopulationWin32.h': No such file or directory

Is there a setting I'm missing or do I need to include the header file in both DLL projects? BTW, I added the unmanged dll output .lib file as a dependency to the managed dll via properties->configuration properties->linker->input->Additional Dependencies.

Your first error 'populationwin32' : is not a class or namespace name means, the compiler has no knowledge about this namespace.

Add an

#include "PopulationWin32.h"

to make this known to Visual Studio.

You also must add the path to your include file, so the compiler can find it. This is described here VC++ Directories, Projects and Solutions, Options Dialog Box and here The #include Directive , for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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