Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Commit 2843cb9

Browse files
committed
Workaround for .NET Native toolchain issue dotnet/corert#5470
The issue is that SupportedAPIs-x86.xml and SupportedAPIs-x64.xml file, as found at C:\Program Files (x86)\Windows Kits\10\App Certification Kit\SupportedAPIs-x??.xml claim that some encoding-neutral methods are actually exported by Windows. This leads .NET Native to generate bindings against them when they don't exist. Until the Windows SDK is fixed, we workaround it by specifying the W unicode suffix for the relevant methods directly. Specifically changed are these methods: * FirstFirstFileEx * CreateMutex * FormatMessage
1 parent d5e1dcf commit 2843cb9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Kernel32/Kernel32.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static partial class Kernel32
9494
/// If the function succeeds, the return value is a search handle used in a subsequent call to FindNextFile or FindClose, and the lpFindFileData parameter contains information about the first file or directory found.
9595
/// If the function fails or fails to locate files from the search string in the lpFileName parameter, the return value is INVALID_HANDLE_VALUE and the contents of lpFindFileData are indeterminate.To get extended error information, call the <see cref="GetLastError"/> function.
9696
/// </returns>
97-
[DllImport(api_ms_win_core_file_l1_2_0, CharSet = CharSet.Unicode)]
97+
[DllImport(api_ms_win_core_file_l1_2_0, EntryPoint = "FindFirstFileExW", ExactSpelling = true, CharSet = CharSet.Unicode)]
9898
public static unsafe extern SafeFindFilesHandle FindFirstFileEx(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, out WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, void* lpSearchFilter, FindFirstFileExFlags dwAdditionalFlags);
9999

100100
/// <summary>
@@ -141,7 +141,7 @@ public static partial class Kernel32
141141
/// If the function succeeds, the return value is the number of TCHARs stored in the output buffer, excluding the terminating null character.
142142
/// If the function fails, the return value is zero. To get extended error information, call <see cref="GetLastError"/>.
143143
/// </returns>
144-
[DllImport(api_ms_win_core_localization_l1_2_0, CharSet = CharSet.Unicode, SetLastError = true)]
144+
[DllImport(api_ms_win_core_localization_l1_2_0, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", ExactSpelling = true, SetLastError = true)]
145145
public static unsafe extern int FormatMessage(FormatMessageFlags dwFlags, void* lpSource, int dwMessageId, int dwLanguageId, StringBuilder lpBuffer, int nSize, IntPtr[] Arguments);
146146

147147
/// <summary>
@@ -483,7 +483,7 @@ public static extern WaitForSingleObjectResult WaitForSingleObject(
483483
/// If the function fails, the return value is NULL. To get extended error information, call GetLastError.
484484
/// If the mutex is a named mutex and the object existed before this function call, the return value is a handle to the existing object, GetLastError returns ERROR_ALREADY_EXISTS, bInitialOwner is ignored, and the calling thread is not granted ownership. However, if the caller has limited access rights, the function will fail with ERROR_ACCESS_DENIED and the caller should use the OpenMutex function.
485485
/// </returns>
486-
[DllImport(api_ms_win_core_synch_l1_2_0, CharSet = CharSet.Unicode, SetLastError = true)]
486+
[DllImport(api_ms_win_core_synch_l1_2_0, EntryPoint = "CreateMutexW", ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]
487487
public static extern unsafe SafeObjectHandle CreateMutex(
488488
[Friendly(FriendlyFlags.Optional | FriendlyFlags.In)] SECURITY_ATTRIBUTES* lpMutexAttributes,
489489
[MarshalAs(UnmanagedType.Bool)] bool bInitialOwner,

0 commit comments

Comments
 (0)