title: Calling C like callback within a thread
body: <p>I have a C static library with,</p>
  
  <p>A callback definition:</p>
  
  <pre><code>typedef  void (*HandleEvents) (enum events eventID, int msgSize, char *msg);
  </code></pre>
  
  <p>A function in the library:</p>
  
  <pre><code>int init(HandleEvents _handleEvents)
  </code></pre>
  
  <p>And another C++ GUI developed in VS. which links this static lib and calls <strong>init</strong> function of the lib giving a function pointer.</p>
  
  <p>init(&amp;CGateway::handleEventsFunc);</p>
  
  <p>where <strong>CGateway::handleEventsFunc</strong> is a static class function.</p>
  
  <p>In a thread in the static lib calls this callback of the C++ GUI. But I got errors of heap corruption.</p>
  
  <p>In sum, there are 2 threads, one in static library and one in Main GUI app. Static library calls Main GUI's class function.</p>
  
  <p>So what is the correct way of calling callback function in a thread?</p>