Massive Confusion with Pointers
Hey,
Even though this uses the WinAPI for threading, the pointers part is general C++, so I think it would probably go best here.
This code is probably invalid, I just created a over-simplified version of what I'm actually trying to accomplish.
Code:
struct KeyBind
{
int * a;
};
DWORD WINAPI thread ( LPVOID lpParam )
{
KeyBind *kb = reinterpret_cast <KeyBind *>(lpParam);
*kb->a = 5;
}
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 );
}
int main ( void )
{
int i = 4;
a ( i ); //i should now equal 5 from the thread...
}
So essentially, I'm trying to change the value of i from with a struct within a thread within a function within the main function.
As of now, I have absolutely no idea what I'm doing anymore. I think I'm over complicating this, which has fried my brain.
To avoid someone saying "Why are you putting one variable into a struct?," The struct has like 5 variables in it, which the thread needs. I just need to change the value of the variables with pointers and stuff so the value of the variable in the function main will be changed.
Any help will be appreciated.
Thanks,
Guitarist809