Hello, how to correctly pass a parameter to a stream function. That is, how to transfer "a" to the Func method? I read that the 4th parameter of the CreateThread method seems to be the field for the parameter.

int main(){ DWORD dID; HANDLE h; int a; h = CreateThread(NULL,0,Func,0,0,&dID); } DWORD WINAPI Func(LPVOID){ ....... } 
  • Hand over a pointer to a - Vladimir Martyanov

1 answer 1

Yes, one of the parameters . Pass the pointer, not the value:

 #include <windows.h> #include <iostream> DWORD WINAPI Func(LPVOID param); int main() { int * param = new int(10); CreateThread( NULL, // default security attributes 0, // use default stack size Func, // thread function name param, // argument to thread function 0, // use default creation flags NULL); ... } DWORD WINAPI Func(LPVOID param) { int * number = static_cast<int*>(param); std::cout << *number << std::endl; delete number; return 0; }