title: C++/CLI - Calling an Unmanaged Function Defined in a DLL
body: <p>I have a DLL which contains unmanaged classes with methods. I'm trying to call those methods from C++/CLI.</p>
  
  <p>My reading has lead me to find that P/Invoke is used to do this. However, I can't seem to find out how to make it work.</p>
  
  <p>In the DLL, the following class is defined:</p>
  
  <pre><code>//Header:
  namespace MathFuncs
  {
      class MyMathFuncs
      {
      public:
          static __declspec(dllexport) double Add(double a, double b);
          static __declspec(dllexport) double Subtract(double a, double b);
          static __declspec(dllexport) double Multiply(double a, double b);
          static __declspec(dllexport) double Divide(double a, double b);
      };
  }
  
  //Source:
  namespace MathFuncs
  {
      double MyMathFuncs::Add(double a, double b) {
          return a + b;
      }
  
      double MyMathFuncs::Subtract(double a, double b) {
          return a - b;
      }
  
      double MyMathFuncs::Multiply(double a, double b) {
          return a * b;
      }
  
      double MyMathFuncs::Divide(double a, double b) {
          if (b == 0) {
              throw new invalid_argument("b cannot be zero!");
          }
          return a / b;
      }
  }
  </code></pre>
  
  <p>From what I've read, the following should declare a method in my C++/CLI code, which I can then call in my code:</p>
  
  <pre><code>class MyMathFuncs {
  public:
  [DllImport("TestDLL.dll")]
      static double Add(double a, double b);
  };
  </code></pre>
  
  <p>Where "TestDLL.dll" is my DLL.</p>
  
  <p>The error I get is at runtime. It says "Unable to find an entry point named 'Add' in DLL 'TestDLL.dll'".</p>
  
  <p>What am I doing wrong? I've read through the MSDN articles on this, but I don't understand it.</p>
  
  <p>Thanks in advance for your help!</p>