VOID MainThread() { Clear(); // Create a random parameter. DWORD dwParm = Random( 90 ); // Create the thread with this parameter. We write “SecondThread” ourselves. HANDLE hThread = CreateThread( "SecondThread", dwParm ); // It may have failed! if ( !hThread ) { PrintF( "Creating the second thread failed." ); return; } // It succeeded! PrintF( "Second thread created with parameter %u.", dwParm ); // The second thread is active while this one is active. // Let’s demonstrate this by holding this thread in a loop for one whole second. // During this second, the other thread should also get its run, printing a // line of text somewhere in the middle of all the text printed in our loop. DWORD dwTime = Time(); DWORD dwCounter = 0; while ( Time() - dwTime < 1000 ) { if ( dwCounter++ % 100000 == 0 ) { PrintF( "\tIn loop, counter is %u. Time left: %u.", dwCounter, 1000 - (Time() - dwTime) ); } } PrintF( "Done." ); // If CreateThread() is successful, the valid handle must be closed! CloseHandle( hThread ); } // And this is the function called by CreateThread() above. // dwParm is the parameter passed in CreateThread() and can be whatever we want it to // be—a number, a pointer, whatever. If more parameters are needed than just one, // organize them into a structure and pass a pointer to the structure to // CreateThread() (the pointer will be cast to a DWORD, then you can cast it back // inside your second thread). DWORD SecondThread( DWORD dwParm ) { // All we need to do for this example is print the parameter passed to us. PrintF( "From Second Thread: %u.", dwParm ); }