Pber
asked on
CreateThread and hwnd
I need to pass a handle to a control to a thread. This is what I've come up with. The problems is in my, hDlgCombo doesn't receive the hDlg handle. How do I pass the handle to the window to the thread and have the called function interpret it properly?
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
MyProc, // thread function
hDlg, // argument to thread function (Handle to a windows control)
0, // use default creation flags
&dwThreadId); // returns the thread identifier
DWORD WINAPI MyProc(LPVOID lpParam)
{
HWND hDlgCombo=*(HWND*)lpParam;
// my processing
}
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
MyProc, // thread function
hDlg, // argument to thread function (Handle to a windows control)
0, // use default creation flags
&dwThreadId); // returns the thread identifier
DWORD WINAPI MyProc(LPVOID lpParam)
{
HWND hDlgCombo=*(HWND*)lpParam;
// my processing
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Pber,
> >HWND hDlgCombo=*(HWND*)lpParam;
Do the following:
HWND hDlgCombo=(HWND)lpParam;
David Maisonave :-)
Cheers!
> >HWND hDlgCombo=*(HWND*)lpParam;
Do the following:
HWND hDlgCombo=(HWND)lpParam;
David Maisonave :-)
Cheers!
Hold on there, Bucko. We need a few more details, using words like "of my app", "to some thread of my/some other app". We need the whole sordid story of what you're trying to do. Who do these threads and dialogs and windows belong to, and what exactly are you trying to intercept and pass on and to whom?
.
.
FYI:
HWND hDlgCombo=*(HWND*)lpParam;
HWND hDlgCombo=(HWND)lpParam;
Both of the above lines are the same from the compiler point of view.
Exactly what type of problems are you having with the code?
And what are you trying to do with the window handle?
HWND hDlgCombo=*(HWND*)lpParam;
HWND hDlgCombo=(HWND)lpParam;
Both of the above lines are the same from the compiler point of view.
Exactly what type of problems are you having with the code?
And what are you trying to do with the window handle?
>>Both of the above lines are the same from the compiler point of view.
Not if the input is a HWND. E.g.
int n = 42;
void* p = (void*)n;
int test = *(int*)p; // p == 42, thus test = *(42); --> bang!
Not if the input is a HWND. E.g.
int n = 42;
void* p = (void*)n;
int test = *(int*)p; // p == 42, thus test = *(42); --> bang!
>>Not if the input is a HWND. E.g.
You're above test does not reflect the correct comparison.
You're comparing apples and oranges.
The following is more accurate comparison:
int main(int argc, char* argv[])
{
int n = 42;
void* p = (void*)&n;
int test = *(int*)p;
printf("%i\n", test); //This will print 42
You're above test does not reflect the correct comparison.
You're comparing apples and oranges.
The following is more accurate comparison:
int main(int argc, char* argv[])
{
int n = 42;
void* p = (void*)&n;
int test = *(int*)p;
printf("%i\n", test); //This will print 42
Disregard my previous post.
jkr,
You're right, there is a difference.
jkr,
You're right, there is a difference.
ASKER
Thanks guys, works like a charm.
HWND hDlgCombo=(HWND*)lpParam;