The thread will concurrently update certain controls as information is processed (i.e. I do some calculations on an item, then add the item to a ListView, so the ListView handle is needed. I guess optimally, it would be better to do all calc's first, then pass back a list of items, then add all items at once...).
The structure was allocated in the caller's caller, here's what the execution trace looks like
(I've highlighted in red all references to the "args" structure along the way):
Code:
DialogFunc1(hwnd, msg, lparam, wparam)
{
case BN_CLICKED:
...
mystruct args = {handle1, handle2, handle3};
DialogBoxParam(..., DialogFunc2, &args);
//mystruct will be on stack at least until EndDialog()
...
}
DialogFunc2(..., lparam)
{
...
WM_INITDIALOG:
//lparam = &args from func1
//pass along &args so we give this window a chance to initialize
PostMessage(hwnd, MY_MSG,0, lparam);
break;
MY_MSG:
hThread = (HANDLE)_beginthreadex(null, 0, Thread, lparam, 0, null);
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
EndDialog(hwnd, null);
//args still on stack from Func1, which is waiting for Func2,
//which is waiting for Thread
...
// yes, even after all that work, I *still* end up blocking the window func :D
// (I'll change it later if I ever get the thread working)
}
__stdcall Thread(void *pArgs)
{
mystruct *args = (mystruct *)pArgs;
HWND handle1 = args->handle1;
HWND handle2 = args->handle2;
...
loop:
Do some calculations
UpdateGUIInfo(handle1, handle2, handle3);
...
return 0;
}
Also, I have MingW's libmsvcrt and also link shlwapi, ole, and comctrl32, but use only limited functions from shlwapi (some string path handling) and comctrl (listview messages) in the thread.