I am not sure how you are creating the thread (or where from)... but if you are using this method (CreateThread) from the main thread lets assume

http://msdn2.microsoft.com/en-us/library/aa374779.aspx

then you should retain the thread handle and pass it straight into SetThreadAffinityMask...

However, if the code that calls SetThreadAffinityMask is on the same thread that you are setting the affinity of, you could get the handle by using (GetCurrentThread)
http://msdn2.microsoft.com/en-us/library/ms683182.aspx

Not really sure if that answers your question or even helps... just a thought...