Code:
// CreateThread.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
void ThreadFunc(LPVOID data);
int _tmain(int argc, _TCHAR* argv[])
{
DWORD threadID;
TCHAR msg[] = "Hello from another thread!";
//Create a run of the mill thread
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc,
(LPVOID)msg, 0, &threadID);
//Wait for the thread to finish. In a real program you would probably
//want to do something here
WaitForSingleObject(hThread,INFINITE);
//Free the handle back to Windows
CloseHandle(hThread);
return 0;
}
void ThreadFunc(LPVOID data)
{
TCHAR *msg = (TCHAR*)data;
MessageBox(NULL, msg, _T("Yo!"), MB_OK | MB_ICONINFORMATION);
}
tmode -nopause