microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.72k stars 308 forks source link

Incompatibility between WindowsAppRuntime.dll and SetDefaultDllDirectories #4403

Open razvan-pricope opened 1 month ago

razvan-pricope commented 1 month ago

Describe the bug

Hello, we are using WindowsAppRuntime (indirectly) from an winui3 desktop application. We noticed that the application does not start when calling SetDefaultDllDirectories. I managed to track the issue to this LoadLibraryExW call when calling it with a relative path (dcompi.dll during my tests) ).

The documentation of LoadLibraryExW states about LOAD_WITH_ALTERED_SEARCH_PATH that:

If this value is used and lpFileName specifies a relative path, the behavior is undefined.

A minimally reproducible example of the behavior (without the entire winui infrastructure, just for demonstration purposes):

int main()
{
    SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
    HMODULE mod = LoadLibraryExW(L"dcompi.dll", nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
    return 0;
}

Steps to reproduce the bug

Run any WindowsAppRuntime app that calls SetDefaultDllDirectories. It should just work.

Expected behavior

No response

Screenshots

No response

NuGet package version

None

Packaging type

No response

Windows version

No response

IDE

Visual Studio 2022

Additional context

No response