title: Callback, specified in QueueUserAPC , does not get called
body: <p>In my code, I use <code>QueueUserAPC</code> to <strong>interrupt</strong> the main thread from his current work in order to invoke some callback first before going back to his previous work.</p>
  
  <pre><code>std::string buffer;
  std::tr1::shared_ptr&lt;void&gt; hMainThread;
  VOID CALLBACK myCallback (ULONG_PTR dwParam) {
      FILE * f = fopen("somefile", "a");
      fprintf(f, "CALLBACK WAS INVOKED!\n");
      fclose(f);
  }
  void AdditionalThread () {
      // download some file using synchronous wininet and store the
      // HTTP response in buffer
      QueueUserAPC(myCallback, hMainThread.get(), (ULONG_PTR)0);
  }
  void storeHandle () {
      HANDLE hUnsafe;
      DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), 
          GetCurrentProcess(), &amp;hUnsafe, 0, FALSE, DUPLICATE_SAME_ACCESS);
      hMainThread.reset(hUnsafe, CloseHandle);
  }
  void startSecondThread () {
      CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AdditionalThread, 0, 0, NULL);
  }
  </code></pre>
  
  <p><code>storeHandle</code> and <code>startSecondThread</code> are exposed to a Lua interpreter which is running in the main thread along with other things. What I do now, is</p>
  
  <ol>
  <li>invoke <code>storeHandle</code> from my Lua interpreter. <code>DuplicateHandle</code> returns a non-zero value and therefore succeeds.</li>
  <li>invoke <code>startSecondThread</code> from my Lua interpreter. The additional thread gets started properly, and <code>QueueUserAPC</code> returns a nonzero value, stating, that all went well.</li>
  <li>as far as I understood <code>QueueUserAPC</code>, <code>myCallback</code> should now get called from the main thread. However, it doesn't.</li>
  </ol>
  
  <p>If <code>QueueUserAPC</code> is the correct way to accomplish my goal (==> see my other <a href="https://stackoverflow.com/questions/1977742/inter-thread-communication-how-to-send-a-signal-to-another-thread">question</a>):</p>
  
  <ul>
  <li>How can I get this working?</li>
  </ul>
  
  <p>If I should some other method to interrupt the main thread:</p>
  
  <ul>
  <li>What other method should I use? (Note that I don't want to use <em>pull</em>-ing method in the main thread for this like <code>WaitForSingleObject</code> or polling. I want that the additional thread <em>push</em>-es it's data straight into the main thread, as soon as possible.)</li>
  </ul>