Hi, I was trying to create a thread from an object member function, and trying to pass 'this' to the CreateThread() function in the thread parameter function. In the thread procedure, I did:
However, it didn't work - I ended up with the wrong object, filled with garbage. Then, I tried doing the pointer-pointer thing:
(Class)& myRef = *(Class*)lpParam;
This time it worked. Does anybody know why I needed to use a pointer-pointer? MSDN says the parameter should be "a pointer to a variable to be passed to the thread". Does CreateThread dereference the parameter, make a copy of it and pass the pointer of the copy to the thread, or what?
Class* temp = this;
CreateThread(..., (LPVOID)&temp, ...);
//in thread procedure:
(Class)& myRef = **(Class**)lpParam;