CTF Flags

Flags that control the calling function's behavior. Used by SHCreateThread and SHCreateThreadWithHandle. In those functions, these values are defined as being of type SHCT_FLAGS.

Constant/value Description
CTF_INSIST
0x00000001
0x00000001. If the attempt to create the thread with CreateThread fails, setting this flag will cause the function pointed to by pfnThreadProc to be called synchronously from the calling thread. This flag can be used only if pfnCallback is NULL.
CTF_THREAD_REF
0x00000002
0x00000002. Hold a reference to the creating thread for the duration of the call to the function pointed to by pfnThreadProc. This reference must have been set with SHSetThreadRef.
CTF_PROCESS_REF
0x00000004
0x00000004. Hold a reference to the Windows Explorer process for the duration of the call to the function pointed to by pfnThreadProc. This flag is useful for Shell extension handlers, which might need to keep the Windows Explorer process from closing prematurely. This action is useful during tasks such as working on a background thread or copying files. For more information, see SHGetInstanceExplorer.
CTF_COINIT_STA
0x00000008
0x00000008. Initialize COM as a Single Threaded Apartment (STA) for the created thread before calling either the optional function pointed to by pfnCallback or the function pointed to by pfnThreadProc. This flag is useful when COM needs to be initialized for a thread. COM will automatically be uninitialized as well.
CTF_COINIT
0x00000008
Equivalent to CTF_COINIT_STA.
CTF_FREELIBANDEXIT
0x00000010
0x00000010. Internet Explorer 6 or later.LoadLibrary will be called on the DLL that contains the pfnThreadProc function to prevent it from being unloaded. After pfnThreadProc returns, the DLL will be freed with FreeLibrary, thereby decrementing the DLL reference count. Pass this flag to prevent the DLL from being unloaded prematurely; for example, by CoFreeUnusedLibraries. Note that if this flag is passed, the pfnThreadProc function must reside in a DLL. This flag is implicit in Windows Vista and later.
CTF_REF_COUNTED
0x00000020
0x00000020. Internet Explorer 6 or later. A thread reference will automatically be created for the created thread and set with SHSetThreadRef. After the pfnThreadProc returns, the thread reference is released and messages are sent until the reference count on the thread reference drops to zero, that is, until threads that are dependent on the created thread have released their references.
CTF_WAIT_ALLOWCOM
0x00000040
0x00000040. Internet Explorer 6 or later. The calling thread waits and pumps COM and SendMessage messages. If the synchronous procedure attempts to send a Windows message with SendMessage to a window hosted on the calling thread, the message will arrive successfully. If the synchronous procedure attempts to use COM to communicate with an STA object hosted on the calling thread, the function call will successfully reach the intended object. The calling thread is open to re-entrance fragility. While the calling thread can handle the synchronous procedure's use of SendMessage and COM, if other threads are using SendMessage or COM to communicate to objects hosted on the calling thread, then these might be unexpected messages or function calls which are processed while the synchronous procedure is completing.
CTF_UNUSED
0x00000080
0x00000080. Internet Explorer 7 or later. Not used.
CTF_INHERITWOW64
0x00000100
0x00000100. Internet Explorer 7 or later. The new thread inherits the Windows-on-Windows 64-bit (WOW64) disable state for the file system redirector.
CTF_WAIT_NO_REENTRANCY
0x00000200
0x00000200. Windows Vista or later. The calling thread blocks all other processes while waiting for the synchronous procedure to run on the new thread. If the synchronous procedure attempts to send a Windows message with SendMessage to a window hosted on the calling thread, this causes the synchronous procedure to deadlock. If the synchronous procedure attempts to use COM to talk to an STA object hosted on the calling thread, this also causes the synchronous procedure to deadlock. The calling thread is protected from all re-entrance concerns by specifying this flag.
CTF_KEYBOARD_LOCALE
0x00000400
0x00000400. Windows 7 or later. Use the keyboard locale from the original thread in the new thread that it spawns.
CTF_OLEINITIALIZE
0x00000800
0x00000800. Windows 7 or later. Initialize COM with the single-threaded apartment (STA) model for the created thread.
CTF_COINIT_MTA
0x00001000
0x00001000. Windows 7 and later. Initialize COM with the multithreaded apartment (MTA) model for the created thread.
CTF_NOADDREFLIB
0x00002000
0x00002000. Windows 7 or later. This flag is essentially the opposite of CTF_FREELIBANDEXIT. This avoids LoadLibrary/FreeLibraryAndExitThread calls that can result in contention for the loader lock. Use CTF_NOADDREFLIB only when the new thread has means to ensure that the code of the original thread procedure will remain loaded. This value should not be used in the context of COM objects, because COM objects must ensure that the DLL stays loaded (normally, COM unloads the DLLs).

Remarks

If no CTF_WAIT_ flag is specified, the calling thread will wait and send SendMessage messages. If the synchronous procedure attempts to send a Windows message with SendMessage to a window hosted on the calling thread, the message will get to the intended window. If the synchronous procedure attempts to use COM to talk to an STA object hosted on the calling thread, the synchronous procedure will deadlock. The calling thread is open to re-entrance fragility. While the calling thread can handle the synchronous procedure's use of SendMessage, if other threads use SendMessage to communicate to an window hosted on the calling thread, then these messages might be unexpected. This can cause them to be processed while the synchronous procedure is completing.

Requirements

Requirement Value
Minimum supported client
Windows 2000 Professional, Windows XP, Windows 7 [desktop apps only]
Minimum supported server
Windows 2000 Server [desktop apps only]
Header
Shlwapi.h