This code works without errors and creates 3 worker threads, keep in mind that you need a
return value as int and
int max_number = 3 and
function[i]:
DWORD WINAPI ThreadProc0(LPVOID param)
{
return 0;
}
DWORD WINAPI ThreadProc1(LPVOID param)
{
return 0;
}
DWORD WINAPI ThreadProc2(LPVOID param)
{
return 0;
}
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)
{
DWORD threadId = 0;
int max_number=3;
typedef DWORD (WINAPI * THREADPROCFN)(LPVOID lpParameter);
THREADPROCFN function[3] = {ThreadProc0,ThreadProc1,ThreadProc2} ;
for (int i = 0; i < max_number; i++)
{
CreateThread( NULL,
0,
function[i],
(LPVOID) i,
0,
NULL
);
}
return 0;
}
Output:
The thread 0x2c4 has exited with code 0 (0x0).
The thread 0x1160 has exited with code 0 (0x0).
The thread 0xc54 has exited with code 0 (0x0).
The program '[3520] Win32Project1.exe' has exited with code 0 (0x0).