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

The LlmAttachThread 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 LLM_ERROR. To get extended error information, call LlmGetLastError.

Remarks

When a client handle is created, it is associated with the thread that created it. If another thread attempts to use the handle, the function will fail because that thread does not own the handle. This prevents other threads from interfering with an operation being performed by the owner thread. The LlmAttachThread function changes the thread that owns the client handle. This is useful when one thread creates the client session and then passes it to a worker thread for processing. The function returns the thread ID of the previous owner, which can be saved and used later to restore ownership of the handle.

This function should normally be called by the new owner thread immediately after it has been created. If the worker thread does not release the handle itself, ownership should be restored to the original thread before the worker thread terminates. Do not use LlmAttachThread to forcibly take ownership of a handle from another thread while a blocking operation is in progress. The handle should only be transferred when no other thread is actively using it.

The dwThreadId parameter is assumed to be a valid thread ID. This function does not verify that the specified thread exists. Specifying an invalid thread ID will orphan the handle until LlmUninitialize is called.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib

See Also

LlmConnect, LlmDisconnect, LlmUninitialize