Creating a Thread

Threads are created by calling the function CreateThread. The function is passed an address of a function (the "thread function") that the new thread will start executing, in much the same way the primary thread starts executing WinMain as an entry point into the application. The thread function always has the following prototype:

DWORD WINAPI ThreadProc(LPVOID lpParameter);

The function is passed an LPVOID pointer that can be used for passing information into the thread from the thread that calls CreateThread. The function returns a DWORD which is the thread exit code. The thread exit code is used in much the same way as the process exit code described earlier in this chapter.

In Listing 5.7 CreateThread is called to create ...

Get Windows® CE 3.0 Application Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.