title: SetThreadAffinityMask Usage
body: <p>i really have a hard time understanding the SetThreadAffinityMask function. Im trying to implement a timer with the QueryPerformanceCounter function but I dont understand how to get the thread affinity right. A guy on msdn posted the following code example:</p>
  
  <pre><code>void HRTimer::StartTimer(void)
  {
      DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0);
      ::QueryPerformanceCounter(&amp;start);
      ::SetThreadAffinityMask(::GetCurrentThread(), oldmask);
  }
  </code></pre>
  
  <p>But when I adopt this code snippet the value for oldmask returned by SetThreadAffinityMask is zero. On MSDN I saw that a return value of zero means that an error occurred. I called GetLastError() and got the error code for ERROR_INVALID_PARAMETER. Now im wondering if the code snippet above isnt correct. Can someone please explain me how to use SetThreadAffinityMask correctly so that QueryPerformanceCounter is for example only called on the first CPU on the system? Or is the above example correct allthough SetThreadAffinityMask returns zero?</p>
  
  <p>Thank you in advance.</p>