1 out of 1 rated this helpful - Rate this topic

SHCreateThread function

Applies to: desktop apps only

Creates a thread.

Syntax

BOOL SHCreateThread(
  __in      LPTHREAD_START_ROUTINE pfnThreadProc,
  __in_opt  void *pData,
  __in      SHCT_FLAGS dwFlags,
  __in_opt  LPTHREAD_START_ROUTINE pfnCallback
);

Parameters

pfnThreadProc [in]

Type: LPTHREAD_START_ROUTINE

A pointer to an application-defined function of the LPTHREAD_START_ROUTINE type. If a new thread was successfully created, this application-defined function is called in the context of that thread. SHCreateThread does not wait for the function pointed to by this parameter to complete before returning to its caller. The application-defined function's return value is the exit code of the thread.

pData [in, optional]

Type: void*

A pointer to an optional application-defined data structure that contains initialization data. It is passed to the function pointed to by pfnThreadProc and, optionally, pfnCallback. This value can be NULL.

dwFlags [in]

Type: SHCT_FLAGS

The flags that control the behavior of the function. One or more of the CTF constants.

pfnCallback [in, optional]

Type: LPTHREAD_START_ROUTINE

A pointer to an optional application-defined function of the LPTHREAD_START_ROUTINE type. This function is called in the context of the created thread before the function pointed to by pfnThreadProc is called. It will also receive pData as its argument. SHCreateThread will wait for the function pointed to by pfnCallback to return before returning to its caller. The return value of the function pointed to by pfnCallback is ignored.

Return value

Type: BOOL

Returns TRUE if the thread is successfully created, or FALSE otherwise. On failure, use GetLastError to retrieve the specific error value as shown here.


if (!SHCreateThread(...))
{
    hr = HRESULT_FROM_WIN32( GetLastError() );
}
else
{
    ....
}

Remarks

The function pointed to by pfnThreadProc and pfnCallback must take the following form.


DWORD WINAPI ThreadProc(LPVOID pData)
{
  ...
}

The function name is arbitrary. The pData parameter points to an application-defined data structure with initialization information.

Requirements

Minimum supported client

Windows 2000 Professional, Windows XP

Minimum supported server

Windows 2000 Server

Header

Shlwapi.h

Library

Shlwapi.lib

DLL

Shlwapi.dll (version 5.0 or later)

See also

CreateThread
CreateProcess
SHCreateThreadRef
SHSetThreadRef
SHGetThreadRef
SHReleaseThreadRef
Shell and Common Controls Versions

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
this function set the last error on failure
use GetLastError() in the failure case



if (!SHCreateThread(...))
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
else
{
....
}