1
votes

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.

1
Have you included the header file for populationwin32::PopulationWin32?Olaf Dietsche
You didn't close the classdeclaration of PopulationWin32 with a semicolon.Timo Geusch
@OlafDietsche Thanks, see my edits above.nalyd88
@TimoGeusch Actually I had used a semicolon just not when I posted the question. I edited the post. Thanks for the comments.nalyd88
This means the compiler misses the path to PopulationWin32.h. You must add it to the compiler's include path.Olaf Dietsche

1 Answers

1
votes

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.