Programming Tips - Win32: How to pass an integer parameter to a thread?

Date: 2015apr20 Update: 2025oct24 Platform: win32 Language: C/C++ Q. Win32: How to pass an integer parameter to a thread? Casting to/from LPVOID gives these errors: warning C4311: 'type cast' : pointer truncation from 'LPVOID' to 'int' warning C4312: 'type cast' : conversion from 'int' to 'LPVOID' of greater size A. Add in an extra cast to INT_PTR like this:
void _cdecl MyThread(LPVOID pParam) { int myNumber = (int)(INT_PTR) pParam; //... } void startThread() { // Start the thread this way const int myNumber = 1234; _beginthread(MyThread, 0, (LPVOID)(INT_PTR) myNumber); }