I have a thread function that looks something like this:
DWORD WINAPI Thread_ProcessFile( LPVOID lpParam ) {
char *filename = (char*)lpParam;
printf( "%s\n", filename );
}
I also have a class that calls CreateThread and uses the above function for the routine address:
void CMyClass::ProcessFile( void ) {
HANDLE tHwnd = 0;
char szBuffer[128];
strcpy( szBuffer, "test_string" );
tHwnd = CreateThread( NULL, 0, Thread_ProcessFile, (LPVOID)szBuffer, 0, NULL );
if ( tHwnd == NULL )
return;
}
The problem is that the routine is receiving/printing a garbage string and not the real thing (eg. random set of characters, if any). If I do this, however:
tHwnd = CreateThread( NULL, 0, Thread_ProcessFile, (LPVOID)"test_string", 0, NULL );
the string is received and printed correctly. How can I properly build a string and pass it to my thread function?