I am having problems obtaining the owner (parent) of my BrowseForFolder dialog box from within my dialog box callback function. The callback function's hwnd parameter is the handle of the BrowseForFolder dialog box, so I tried using GetParent(hwnd) to obtain the parent of the dialog box but it does not seem to be working.
I made sure to set the hwndOwner member of the BROWSEINFO struct:
Code:
BROWSEINFO bi;
ZeroMemory(&bi, sizeof(bi));
bi.hwndOwner = hwnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = displayName;
...
setting its owner to the current window.

Here is my simple callback function:
Code:
int CALLBACK
BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
    switch(uMsg)
    {
        case BFFM_INITIALIZED:
        {
            HWND hGamePathEdit = GetDlgItem(GetParent(hwnd), IDC_GAMEPATHEDIT);
            char path[SendMessage(hGamePathEdit, WM_GETTEXTLENGTH, 0, 0) + 1];

            SendMessage(hGamePathEdit, WM_GETTEXT, (WPARAM)sizeof(path), (LPARAM)path);
            SendMessage(hwnd, BFFM_SETSELECTION, (WPARAM)TRUE, (LPARAM)path);

            break;
        }
    }
    return 0;
}
I believed that calling GetParent on hwnd would give me the handle for the parent window in which I had called SHBrowseForFolder (the window containing the IDC_GAMEPATHEDIT control I am trying to send a message to); however it did not work at all. To rule out any other conflicts, I passed the parent window handle to the callback function through the lpData param instead and used (HWND)lpData in place GetParent(hwnd), and that worked perfectly. Also, I have used GetParent() successfully in many other dialog boxes.
So I guess my question is, why does calling GetParent from within the BrowseForFolder dialog box callback function not return me the handle to the window that initiated the dialog box? What am I doing wrong here??