user32: Implement GetWindowModuleFileName with tests (try 2)

Dmitry Timoshkov dmitry at codeweavers.com
Tue Apr 1 00:11:14 CDT 2008


"Alexandre Julliard" <julliard at winehq.org> wrote:

> "Maarten Lankhorst" <m.b.lankhorst at gmail.com> writes:
> 
>> @@ -3121,9 +3133,21 @@ UINT WINAPI GetWindowModuleFileNameA( HWND hwnd, LPSTR lpszFileName, UINT cchFil
>>   */
>>  UINT WINAPI GetWindowModuleFileNameW( HWND hwnd, LPWSTR lpszFileName, UINT cchFileNameMax)
>>  {
>> -    FIXME("GetWindowModuleFileNameW(hwnd %p, lpszFileName %p, cchFileNameMax %u) stub!\n",
>> -          hwnd, lpszFileName, cchFileNameMax);
>> -    return 0;
>> +    HINSTANCE hInst;
>> +    UINT ret;
>> +    TRACE("hwnd %p, lpszFileName %p, cchFileNameMax %u\n", hwnd, lpszFileName, cchFileNameMax);
>> +
>> +    hInst = (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE);
>> +    if (!hInst)
>> +    {
>> +        if (hwnd == GetDesktopWindow() || !IsWindow(hwnd))
>> +            return 0;
>> +        hInst = GetModuleHandleW(0);
>> +    }
>> +
>> +    ret = GetModuleFileNameW(hInst, lpszFileName, cchFileNameMax);
>> +    TRACE("--> %d %s\n", ret, debugstr_wn(lpszFileName, ret));
>> +    return ret;
> 
> This won't work across processes.

Looks like GetWindowModuleFileName is not supposed to work for other
process windows, at least in the following snippet both GetWindowLongPtr
and GetWindowModuleFileName return 0 but don't change the last error value
under XP although FindWindow returns a valid window handle:

hwnd = FindWindow("Shell_TrayWnd", NULL);
SetLastError(0xdeadbeef);
ret = GetWindowModuleFileNameA(hwnd, buf, sizeof(buf));
printf("hwnd %p, ret %u, buf \"%s\", error %u\n", hwnd, ret, buf, GetLastError());

SetLastError(0xdeadbeef);
hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
printf("hwnd %p, hinst %u, error %u\n", hwnd, ret, GetLastError());

GetWindowLong(hwnd, GWL_STYLE) returns a valid style. Both APIs behave the same
way for the desktop window.

So the above implementation of GetWindowModuleFileName looks correct except
a special case for the desktop window (GetWindowLong() should be fixed instead).

-- 
Dmitry.



More information about the wine-devel mailing list