View Full Version : Multithreading API functions and .NET

01-10-2007, 03:48 PM
So I'm porting some classes from Win32 to .NET. One of these classes, based on TThread, calls SetThreadAffinityMask():

DWORD_PTR WINAPI SetThreadAffinityMask(
__in HANDLE hThread,
__in DWORD_PTR dwThreadAffinityMask


I haven't had problems calling other API functions, but with this one I can't find the parameter needed. When I try to pass the handle of the Thread, this handle doesn't fit because it is of "Thread" type, not "Integer". I tried using IntPtr, but it doesn't seem capable to convert the handle. Is there a way to obtain the API handle of the thread? Just thought maybe I should call another API function to get the current thread handle, but if you have any idea please let me know.

Thanks! :D

01-10-2007, 08:01 PM
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


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)

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

01-10-2007, 08:12 PM
That's what I supposed, I'll try it at home. Thanks!