WhoisAttachThread Function  
 
DWORD WINAPI WhoisAttachThread(
  HCLIENT hClient  
  DWORD dwThreadId  
);

The WhoisAttachThread function attaches the specified client handle to another thread.

Parameters

hClient
Handle to the client session.
dwThreadId
The ID of the thread that will become the new owner of the handle. A value of zero specifies that the current thread should become the owner of the client handle.

Return Value

If the function succeeds, the return value is the thread ID of the previous owner. If the function fails, the return value is WHOIS_ERROR. To get extended error information, call WhoisGetLastError.

Remarks

When a client handle is created, it is associated with the current thread that created it. Normally, if another thread attempts to perform an operation using that handle, an error is returned since it does not own the handle. This is used to ensure that other threads cannot interfere with an operation being performed by the owner thread. In some cases, it may be desirable for one thread in a client application to create the client handle, and then pass that handle to another worker thread. The WhoisAttachThread function can be used to change the ownership of the handle to the new worker thread. By preserving the return value from the function, the original owner of the handle can be restored before the worker thread terminates.

This function should be called by the new thread immediately after it has been created, and if the new thread does not release the handle itself, the ownership of the handle should be restored to the parent thread before it terminates. Under no circumstances should WhoisAttachThread be used to forcibly release a handle allocated by another thread while a blocking operation is in progress. To cancel an operation, use the WhoisCancel function and then release the handle after the blocking function exits and control is returned to the current thread.

Note that the dwThreadId parameter is presumed to be a valid thread ID and no checks are performed to ensure that the thread actually exists. Specifying an invalid thread ID will orphan the handle until the WhoisUninitialize function is called.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cstools10.h
Import Library: cswhov10.lib

See Also

WhoisCancel, WhoisAsyncConnect, WhoisConnect, WhoisDisconnect, WhoisUninitialize