Summary:

The Daytona release of Windows NT (scheduled for release in Q2 '94) will introduce APIs for getting and setting processor affinity. They will be exported from kernel32.dll and their prototypes will be in winbase.h.

At the current time, you can obtain a header file, import library, and DLL which provide this functionality in Library 6 of the MSWIN32 forum on CompuServe. The file is called affin.zip. It is intended that these files be used only until the time that Daytona
 is released. At that time, the supported Win32 APIs should be used.

The APIs are as follows:

GetProcessAffinityMask()
------------------------

BOOL GetProcessAffinityMask( HANDLE, LPDWORD, LPDWORD );

HANDLE  hProcess,
LPDWORD lpProcessAffinityMask,
LPDWORD lpSystemAffinityMask

This function returns the affinity masks for the given process and for the system. The process affinity mask is a bit vector in which each bit that is set represents a processor on which the process can be run. The system affinity mask is a bit vector in whic
h each bit set represents a processor in the machine.

The process affinity mask is a proper subset of the system affinity mask.

Arguments:

hProcess - Supplies an open handle to the specified process. The
   handle must have PROCESS_QUERY_INFORMATION access.

lpProcessAffinityMask - Supplies the address of a DWORD that returns the
   specified process' affinity mask.

lpSystemAffinityMask - Supplies the address of a DWORD that returns the 
   system affinity mask.

Return Value:

TRUE - The API was successful

FALSE - The operation failed. Extended error status is available using 
   GetLastError().

SetThreadAffinityMask()
-----------------------

DWORD SetThreadAffinityMask( HANDLE, DWORD );

HANDLE hThread,
DWORD  dwThreadAffinityMask

This function sets the given thread's processor affinity mask. The thread affinity mask is a bit vector in which each bit that is set represents a processor on which the thread is allowed to run. The affinity mask MUST be a proper subset of the containing pro
cess' process level affinity mask, which can be obtained using GetProcessAffinityMask().

Arguments:

hThread - Supplies a handle to the thread whose priority is to be set.  
   The handle must have THREAD_SET_INFORMATION access.

dwThreadAffinityMask - Supplies the affinity mask to be used for the 
   specified thread.

Return Value:

nonzero - The API was successful. The return value is the previous
   affinity mask for the thread.

zero - The operation failed. Extended error status is available using 
   GetLastError().

More Information:

There are two differences between the implementation in affin.dll and the implementation that will be included in Daytona:

1) When the APIs in affin.dll fail, they DO NOT set the last error 
   value. Do not use GetLastError().

2) The APIs in affin.dll do not enforce that thread affinity must be an 
   exact subset of process affinity. For example, if your process 
   affinity is 1 and you request a thread affinity of 3, these APIs will 
   allow this. The released APIs will not allow this; if you request an 
   affinity bit that is not set in your process affinity, the API will 
   fail.

   Windows NT will enforce

      if((ThreadAffinityMask & ProcessAffinityMask)!=ThreadAffinityMask) 
      {
         FailTheAPI();
      }

   The implementaion in affin.dll only checks

      if( !(ThreadAffinityMask & ProcessAffinityMask) ) 
      {
         FailTheAPI();
      }
