title: DLL CreateThread, DisableThreadLibraryCalls and _beginthreadex
body: <p>I'm trying to understand what the difference is between <code>CreateThread</code> and <code>_beginthreadex</code> and why calling <code>DisableThreadLibraryCalls</code> only prevents threads installed with <code>_beginthreadex</code> from executing.</p>
  
  <p>I have a project which is a DLL, an old DLL, this is a win32 dll and I am tasked with porting it to win64.  One thing that tripped me up was a call in <code>DLLMain</code> to <code>DisableThreadLibraryCalls</code>.</p>
  
  <p>My threads were installed with <code>_beginthreadex</code>, the body of the threads was never being executed cause of the call to <code>DisableThreadLibraryCalls</code>.  Once I removed this, the threads were working correctly.</p>
  
  <p>Now I've found that other threads in the same DLL are started with <code>CreateThread</code>, I then thought was the call to <code>DisableThreadLibraryCalls</code> there to prevent these threads from executing so I put it back and found that the threads created with <code>CreateThread</code> are executed regardless of if <code>DisableThreadLibraryCall</code>s is present or not but threads created with <code>_beginthreadex</code> are disabled.</p>
  
  <p>Why?  I can't find anything on:</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms682579(v=vs.85).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/ms682579(v=vs.85).aspx</a></p>
  
  <p>That describes why this is happening.</p>