PDA

View Full Version : Multithreading API functions and .NET



cronodragon
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
);

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

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

billy1380
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

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...

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