You also nee to wait for the thread to actually run.
You set i = 4, then execute function a(), but function a() creates the thread and immediately returns. Expecting the thread to execute is undefined behavior. You should either WaitForSingleObject(hThread , INFINITE) on the threads handle, or put some signalling in place to let main() know when the thread has actually finished its work. Also, always close the threads handle when you are finished or it will leak system resources. If you create a lot of threads without freeing the handles after they exit, eventually windows will refuse to start any more threads.
Code:
DWORD WINAPI thread ( LPVOID lpParam ){
KeyBind *kb = reinterpret_cast <KeyBind *>(lpParam);
*kb->a = 5;
return 0;
}
void a ( int &var )
{
KeyBind kb;
*kb.a = var;
DWORD dwThreadId;
///create the thread
HANDLE hThread = CreateThread ( NULL, 0, keythread, reinterpret_cast<LPVOID>(&kb), 0, &dwThreadId );
WaitForSingleObject(hThread , INFINITE);
CloseHandle(hThread);
}
int main ( void ){
int i = 4;
a ( i ); //i should now equal 5 from the thread...
}