views:

27

answers:

1

I have a project called ManagedWrapper that is Managed C++ and builds as a DLL.

I have a second project called MyManagedTest that is Managed C++ and builds as a DLL.

When I try to include a header from ManagedWrapper in MyManagedTest, I get linker LNK2020 errors. I then add a reference to ManagedWrapper in "Frameworks and References" but this causes compiler errors saying that classes in ManagedWrapper are already defined (looks like it is trying to define them again in MyManagedTest because I included header files), error C2011.

What is the proper way to include classes from ManagedWrapper into MyManagedTest?

Thanks.

A: 

You should use #include for native class declarations and #import for managed class declarations. Adding a reference is the same as #import.

BTW, "Managed C++" is not the correct name for using C++ with .NET in VS2008. That feature is C++/CLI. Earlier versions of Visual C++ had a very buggy syntax called "Managed Extensions for C++" which was often referred to as "Managed C++" and should never be used.

Ben Voigt
That wasn't really what I was going for, but thanks for helping me understand proper terminology.
Ben
The first sentence is my answer. Don't use `#include` for header files containing managed classes that exist in another DLL. Use `#import` instead (or add a reference, which is the same as `#import`).
Ben Voigt