Programming Tips - How do I pass an integer to a thread? Casting to/from LPVOID gives these errors:

Date: 2015apr20 Platform: win32 Q. How do I pass an integer 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; //... } // Start the thread this way _beginthread(MyThread, 0, (LPVOID)(INT_PTR) myNumber);