title: How to create an object from a DLL file in c++ at runtime?
body: <p>I have a DLL file which has a class called trial and it contains a function called test, I have another project in which I loaded the DLL using the loadlibrary function from the windows module, now I want to know how to create an object of type trial in the new project.</p>
  
  <p>I tried defining the class as "class __declspec(dllexport) trial" but I don't know how to create an object in the main file now.</p>
  
  <p>Trail.h is as follows:</p>
  
  <pre><code>class __declspec(dllexport) TRIALSHARED_EXPORT Trial
  {
  public:
      Trial();
      void test();
  };
  </code></pre>
  
  <p>Trail.cpp is as follows:</p>
  
  <pre><code>extern "C"{
  Trial::Trial(){
      cout&lt;&lt;"object is created"&lt;&lt;endl;
  }
      void Trial:: test(){
      cout&lt;&lt;"dynamic thingy"&lt;&lt;endl;
  }
  }
  </code></pre>
  
  <p>The main function is as follows:</p>
  
  <pre><code>int main()
  {
      HINSTANCE here=LoadLibrary(L"C:\\Users\\vinay\\Documents\\qt c++\\build-trial-Desktop_Qt_5_12_0_MinGW_64_bit-Debug\\debug\\trial.dll");
      if(!here){
          cout&lt;&lt;"could not load the lib"&lt;&lt;std::endl;
      }
      else{
          cout&lt;&lt;"library loaded"&lt;&lt;endl;
          typedef void(*FNPTR)();
          FNPTR fn=FNPTR(GetProcAddress(here,"Trial"));
          fn();
      }
  }
  </code></pre>