[USER32] Support loading icons from data file module (#6065)

GetModuleFileName() fails on LOAD_LIBRARY_AS_DATAFILE causing LoadImage to fail.
Use a fake filename for LR_SHARED (with same format as Windows).
This may not be a good design, but it does match Windows' behaviour.

+ Added test.
This commit is contained in:
Whindmar Saksit 2023-12-17 22:11:50 +01:00 committed by GitHub
parent 8f349ab3c2
commit 82c07abf1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 1 deletions

View file

@ -1454,7 +1454,21 @@ CURSORICON_LoadImageW(
RtlInitUnicodeString(&ustrRsrc, lpszName);
}
if(hinst)
if(LDR_IS_RESOURCE(hinst))
{
/* We don't have a real module for GetModuleFileName, construct a fake name instead.
* GetIconInfoEx reveals the name used by Windows. */
LPCWSTR fakeNameFmt = sizeof(void*) > 4 ? L"\x01%016IX" : L"\x01%08IX";
ustrModule.MaximumLength = 18 * sizeof(WCHAR);
ustrModule.Buffer = HeapAlloc(GetProcessHeap(), 0, ustrModule.MaximumLength);
if (!ustrModule.Buffer)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
ustrModule.Length = wsprintfW(ustrModule.Buffer, fakeNameFmt, hinst) * sizeof(WCHAR);
}
else if(hinst)
{
DWORD size = MAX_PATH;
/* Get the module name string */