title: Export native type from C++/CLI project
body: <p>How do I export the methods of a native class defined in a C++/CLI project? Here's what I have:</p>
  
  <p>The .h file:</p>
  
  <pre><code>#pragma once
  
  #ifdef COMPILE_PRODUCER_LIB
    #define PRODUCER_LIB_EXPORT __declspec(dllexport)
  #else
    #define PRODUCER_LIB_EXPORT __declspec(dllimport)
  #endif
  
  public class PRODUCER_LIB_EXPORT MySecondNativeClass {
  public:
    MySecondNativeClass(int val);
  
    int getValue() const;
  
  private:
    int m_value;
  };
  </code></pre>
  
  <p>The .cpp file:</p>
  
  <pre><code>#include "stdafx.h"
  #include "MySecondNativeClass.h"
  
  MySecondNativeClass::MySecondNativeClass(int val) {
    this-&gt;m_value = val;
  }
  
  int MySecondNativeClass::getValue() const {
    return this-&gt;m_value;
  }
  </code></pre>
  
  <p>Using this class in the same project works fine, but using it in another (C++/CLI) project gives me "unresolved external symbol" linker errors. (<code>COMPILE_PRODUCER_LIB</code> is a preprocessor definition defined only in the project that contains the class.)</p>
  
  <p>I've created a small solution (for Visual Studio 2010) that shows the problem (download at the end of <a href="http://manski.net/2012/01/09/passing-native-pointers-across-ccli-assembly-boundaries/" rel="nofollow">this page</a>). There, the native class <code>MySecondNativeClass</code> is defined in the project "ManagedProviderLib" and is being used in "ExternalTestClass.cpp" (in project "ManagedExternalLib").</p>