I want to pass an HANDLE and a HWND variables to a _beginthreadex function, I don't want to set those variable global.
that's what i've tried :
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR
lpCmdLine, int nShowCmd)
{
HANDLE t = NULL;
HWND wnd = NULL;
// initialization of wnd and t by their functions
PVOID args[2];
args[0] = &t;
args[1] = &wnd;
_beginthreadex(NULL, 0, threadfunc, args, NULL,NULL,NULL);
// doing some additional stuff
return 0;
}
unsigned int __stdcall threadfunc(PVOID args){
waitforsingleobject(*(PHANDLE)args[0], INFINITE);
EnableWindow((PHWND)args[1]) ;
return 0;
}
this unfortunately does'nt work.. an ideas?
It doesn't work because you are not type-casting
args
correctly. You would need something more like this instead:Or, using dynamic allocation:
A better solution is to use a struct instead of an array:
Or, using dynamic allocation: