microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
1.99k stars 84 forks source link

LocalExternFunctions should use `DefaultDllImportSearchPaths` #1212

Closed elachlan closed 1 week ago

elachlan commented 2 weeks ago

Standard PInvokes generated by CsWin32 have DefaultDllImportSearchPaths attribute applied, but LocalExternFunction seems to be missing it.

Example:

[SupportedOSPlatform("windows10.0.15063")]
internal static winmdroot.Foundation.BOOL SetProcessDpiAwarenessContext(winmdroot.UI.HiDpi.DPI_AWARENESS_CONTEXT value)
{
    Marshal.SetLastSystemError(0);
    winmdroot.Foundation.BOOL __retVal = LocalExternFunction(value);
    Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
    return __retVal;

    [DllImport("USER32.dll", ExactSpelling = true, EntryPoint = "SetProcessDpiAwarenessContext")]
    static extern winmdroot.Foundation.BOOL LocalExternFunction(winmdroot.UI.HiDpi.DPI_AWARENESS_CONTEXT value);
}