title: How to pass an object to a thread in C++ CLI WinForms?
body: <p>I am working on windows forms c++ project,</p>
  <p>I am able to laodlibrary my.dll and get returned Object from dll then the call dll methods inside a button_click (winform.h)</p>
  <p>I need to use the same Object and call a DLL method in a thread how to do this? my current code as follows</p>
  <p>Imy.h is an interface class object, this interface is derived by dll class</p>
  <pre><code>public ref class MyForm : public System::Windows::Forms::Form
  {
  
  public:
    void mythread(Imy &amp;pImy) {//the returned object in button_click object should be pass to here
      //and call  pImy-&gt;callmyfunc2(&quot;test&quot;);
  }
  
  
  private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
      typedef Imy* (*PFN_Factory)();
      
      HINSTANCE hDLL = LoadLibrary(L&quot;my.dll&quot;); // Handle to DLL
      Imy* pImy = NULL;
      PFN_Factory functionPtr;
      
      functionPtr = reinterpret_cast&lt;PFN_Factory&gt;(GetProcAddress(hDLL, &quot;CreateObject&quot;)); // Get the function pointer
      pImy = functionPtr(); // Get pointer to object
  
      pImy -&gt;callmyfunc1(); // call method 1st from the returned object
  
      //pImy -&gt;callmyfunc2(&quot;test&quot;); // this should be run in a thread  
      
      ThreadStart^ ThreadMethod1 = gcnew ThreadStart(pImy , &amp;MyForm::mythread); // does not work i want to know how to this
      Thread^ MyThread1 = gcnew Thread(ThreadMethod1);
      MyThread1-&gt;Start();
  }
  </code></pre>