|
-
August 30th, 2011, 05:55 AM
#1
CreateThread and few arguments
Hey
I'm stuck with the following code. I need to pass a few variables address to new thread to got a shared access to them but the way I choose seems doesn't work. I got in new thread a good pointer to params class but bool and intereger variable addresses are not proper. Where can be the problem??
Thanks!
#include"threads.h"
class params
{
public:
bool* bl;
int* i;
HANDLE* h;
};
DWORD WINAPI ThreadProc(
__in LPVOID lpParameter
)
{
bool* p_b;
int* p_i;
HANDLE h;
params* ptr=(params*)lpParameter;
p_b=ptr->bl; //that's the first problem (often even 0 value for pointer)
p_i=ptr->i; //that's the second problem
h=(*ptr->h);
return 0;
}
void initThread()
{
bool a=true;
int b=1;
HANDLE h=CreateMutex(NULL,TRUE,L"TEST");
params prm;
prm.bl=&a;
prm.h=&h;
prm.i=&b;
CreateThread(0,0,ThreadProc,&prm,0,0);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|