[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9418
  • Last Modified:

CreateThread Code Sample

I need a code sample of how to use the CreateThread Win32 function.
1 Solution
// int this example, we set it up so that child processes do not
// inherit security attributes...

DWORD dwThreadId;
DWORD dwExitCode;
long lParms = 12345;   // some 32 bit value to pass to your function;

HANDLE hThread = CreateThread(NULL,                              // pointer to security attributes
                                            0,                              // initial thread stack size
                                            YourThreadFunction,   // pointer to thread function
                                            &lParms,              // argument for new thread
                                            0,                              // creation flags
                                            &dwThreadId           // pointer to receive thread ID

// now you can do things like:  WaitForSingleObhect(hThread, INFINITE);
// or: GetExitCodeThread(hThread, &dwExitCode);

Your thread function would be declared something like:

UINT YourThreadFunction(LPVOID lParam){}

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now