title: Instantiate a class in exported DLL function using getProcAddress
body: <p>I have following .h code for DLL and using getProcAddress to consume DLL in another code.</p>
  
  <pre><code>// MathFuncsDll.h
  
  #ifdef MATHFUNCSDLL_EXPORTS
  #define MATHFUNCSDLL_API __declspec(dllexport) 
  #else
  #define MATHFUNCSDLL_API __declspec(dllimport) 
  #endif
  
  namespace MathFuncs
  {
      // This class is exported from the MathFuncsDll.dll
      class MyMathFuncs
      {
      public:
          int x = 10;
          MyMathFuncs();
  
             // Returns a + b + x
             MATHFUNCSDLL_API double Add(double a, double b); 
  
      };
  }
  </code></pre>
  
  <p>And corresponding .cpp code is </p>
  
  <pre><code>// MathFuncsDll.cpp : Defines the exported functions for the DLL application. 
  //
  
  #include "stdafx.h"
  #include "MathFuncsDll.h"
  #include &lt;stdexcept&gt;
  
  using namespace std;
  
  namespace MathFuncs
  {
      MyMathFuncs ::MyMathFuncs()
      {
              x = 10;
      }
  
      double MyMathFuncs::Add(double a, double b)
      {
          return a + b + x;
      }
  
  }
  </code></pre>
  
  <p>The function Add is exported and it adds a and b along with initial value of x = 10. </p>
  
  <p>I have created a DLL file of same and calling the functions using LoadLibrary and GetProcAddress. </p>
  
  <p>The code works fine when I do not use constructor and directly add 10 i.e a + b + 10. But it fails when I do a + b + x, and basically constructor is not called.</p>
  
  <p>How to instantiate such object using GetProcAddress so that when I load DLL and call function I get instantiated object method.  </p>