"while ( ( result = ::WaitForSingleObject( hThread, 50 ) ) == WAIT_TIMEOUT )"

this line gives me the Acess Violation.