|
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
#pragma warning disable CS1591,CS1573,CS0465,CS0649,CS8019,CS1570,CS1584,CS1658,CS0436,CS8981
using global::System;
using global::System.Diagnostics;
using global::System.Diagnostics.CodeAnalysis;
using global::System.Runtime.CompilerServices;
using global::System.Runtime.InteropServices;
using global::System.Runtime.Versioning;
using winmdroot = global::Windows.Win32;
namespace Windows.Win32
{
/// <content>
/// Contains extern methods from "KERNEL32.dll".
/// </content>
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Windows.CsWin32", "0.3.151+58e949951d.RR")]
internal static partial class PInvokeCore
{
/// <summary>Closes an open object handle.</summary>
/// <param name="hObject">A valid handle to an open object.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>. If the application is running under a debugger, the function will throw an exception if it receives either a handle value that is not valid or a pseudo-handle value. This can happen if you close a handle twice, or if you call <b>CloseHandle</b> on a handle returned by the <a href="https://docs.microsoft.com/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea">FindFirstFile</a> function instead of calling the <a href="https://docs.microsoft.com/windows/desktop/api/fileapi/nf-fileapi-findclose">FindClose</a> function.</para>
/// </returns>
/// <remarks>
/// <para>The <b>CloseHandle</b> function closes handles to the following objects: </para>
/// <para>This doc was truncated.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/handleapi/nf-handleapi-closehandle#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.0")]
internal static winmdroot.Foundation.BOOL CloseHandle(winmdroot.Foundation.HANDLE hObject)
{
Marshal.SetLastSystemError(0);
winmdroot.Foundation.BOOL __retVal = LocalExternFunction(hObject);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "CloseHandle"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern winmdroot.Foundation.BOOL LocalExternFunction(winmdroot.Foundation.HANDLE hObject);
}
/// <summary>Frees the specified global memory object and invalidates its handle.</summary>
/// <param name="hMem">
/// <para>A handle to the global memory object. This handle is returned by either the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalalloc">GlobalAlloc</a> or <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalrealloc">GlobalReAlloc</a> function. It is not safe to free memory allocated with <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-localalloc">LocalAlloc</a>.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalfree#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is <b>NULL</b>. If the function fails, the return value is equal to a handle to the global memory object. To get extended error information, call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>.</para>
/// </returns>
/// <remarks>
/// <para>If the process examines or modifies the memory after it has been freed, heap corruption may occur or an access violation exception (EXCEPTION_ACCESS_VIOLATION) may be generated. The <b>GlobalFree</b> function will free a locked memory object. A locked memory object has a lock count greater than zero. The <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globallock">GlobalLock</a> function locks a global memory object and increments the lock count by one. The <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalunlock">GlobalUnlock</a> function unlocks it and decrements the lock count by one. To get the lock count of a global memory object, use the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalflags">GlobalFlags</a> function. If an application is running under a debug version of the system, <b>GlobalFree</b> will issue a message that tells you that a locked object is being freed. If you are debugging the application, <b>GlobalFree</b> will enter a breakpoint just before freeing a locked object. This allows you to verify the intended behavior, then continue execution.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalfree#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.1.2600")]
internal static winmdroot.Foundation.HGLOBAL GlobalFree(winmdroot.Foundation.HGLOBAL hMem)
{
Marshal.SetLastSystemError(0);
winmdroot.Foundation.HGLOBAL __retVal = LocalExternFunction(hMem);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "GlobalFree"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern winmdroot.Foundation.HGLOBAL LocalExternFunction(winmdroot.Foundation.HGLOBAL hMem);
}
/// <summary>Retrieves the thread identifier of the calling thread.</summary>
/// <returns>The return value is the thread identifier of the calling thread.</returns>
/// <remarks>Until the thread terminates, the thread identifier uniquely identifies the thread throughout the system.</remarks>
[DllImport("KERNEL32.dll", ExactSpelling = true),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("windows5.1.2600")]
internal static extern uint GetCurrentThreadId();
/// <summary>Returns the locale identifier for the system locale.Note Any application that runs only on Windows Vista and later should use GetSystemDefaultLocaleName in preference to this function.</summary>
/// <returns>Returns the locale identifier for the system default locale, identified by <a href="https://docs.microsoft.com/windows/desktop/Intl/locale-system-default">LOCALE_SYSTEM_DEFAULT</a>.</returns>
/// <remarks>This function can retrieve data from <a href="https://docs.microsoft.com/windows/desktop/Intl/custom-locales">custom locales</a>. Data is not guaranteed to be the same from computer to computer or between runs of an application. If your application must persist or transmit data, see <a href="https://docs.microsoft.com/windows/desktop/Intl/using-persistent-locale-data">Using Persistent Locale Data</a>.</remarks>
[DllImport("KERNEL32.dll", ExactSpelling = true),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("windows5.0")]
internal static extern uint GetSystemDefaultLCID();
/// <summary>Returns the locale identifier of the current locale for the calling thread.Note This function can retrieve data that changes between releases, for example, due to a custom locale.</summary>
/// <returns>
/// <para>Returns the <a href="https://docs.microsoft.com/windows/desktop/Intl/locale-identifiers">locale identifier</a> of the locale associated with the current thread. <b>Windows Vista</b>: This function can return the identifier of a <a href="https://docs.microsoft.com/windows/desktop/Intl/custom-locales">custom locale</a>. If the current thread locale is a custom locale, the function returns <a href="https://docs.microsoft.com/windows/desktop/Intl/locale-custom-constants">LOCALE_CUSTOM_DEFAULT</a>. If the current thread locale is a supplemental custom locale, the function can return <a href="https://docs.microsoft.com/windows/desktop/Intl/locale-custom-constants">LOCALE_CUSTOM_UNSPECIFIED</a>. All supplemental locales share this locale identifier.</para>
/// </returns>
/// <remarks>
/// <para>When an application process launches, it uses the Standards and Formats variable for the locale. For more information, see <a href="https://docs.microsoft.com/windows/desktop/Intl/nls-terminology">NLS Terminology</a>. When a new thread is created in a process, it inherits the locale of the creating thread. This locale can be either the default Standards and Formats locale or a different locale set for the creating thread in a call to <a href="https://docs.microsoft.com/windows/desktop/api/winnls/nf-winnls-setthreadlocale">SetThreadLocale</a>. <b>GetThreadLocale</b> and <b>SetThreadLocale</b> can be used to modify the locale of the new thread.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-getthreadlocale#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[DllImport("KERNEL32.dll", ExactSpelling = true),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[SupportedOSPlatform("windows5.0")]
internal static extern uint GetThreadLocale();
/// <summary>Allocates the specified number of bytes from the heap. (GlobalAlloc)</summary>
/// <param name="uFlags"></param>
/// <param name="dwBytes">The number of bytes to allocate. If this parameter is zero and the <i>uFlags</i> parameter specifies <b>GMEM_MOVEABLE</b>, the function returns a handle to a memory object that is marked as discarded.</param>
/// <returns>
/// <para>If the function succeeds, the return value is a handle to the newly allocated memory object. If the function fails, the return value is <b>NULL</b>. To get extended error information, call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>.</para>
/// </returns>
/// <remarks>
/// <para>Windows memory management does not provide a separate local heap and global heap. Therefore, the <b>GlobalAlloc</b> and <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-localalloc">LocalAlloc</a> functions are essentially the same. The movable-memory flags <b>GHND</b> and <b>GMEM_MOVABLE</b> add unnecessary overhead and require locking to be used safely. They should be avoided unless documentation specifically states that they should be used. New applications should use the <a href="https://docs.microsoft.com/windows/desktop/Memory/heap-functions">heap functions</a> to allocate and manage memory unless the documentation specifically states that a global function should be used. For example, the global functions are still used with Dynamic Data Exchange (DDE), the clipboard functions, and OLE data objects. If the <b>GlobalAlloc</b> function succeeds, it allocates at least the amount of memory requested. If the actual amount allocated is greater than the amount requested, the process can use the entire amount. To determine the actual number of bytes allocated, use the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalsize">GlobalSize</a> function. If the heap does not contain sufficient free space to satisfy the request, <b>GlobalAlloc</b> returns <b>NULL</b>. Because <b>NULL</b> is used to indicate an error, virtual address zero is never allocated. It is, therefore, easy to detect the use of a <b>NULL</b> pointer. Memory allocated with this function is guaranteed to be aligned on an 8-byte boundary. To execute dynamically generated code, use the <a href="https://docs.microsoft.com/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc">VirtualAlloc</a> function to allocate memory and the <a href="https://docs.microsoft.com/windows/desktop/api/memoryapi/nf-memoryapi-virtualprotect">VirtualProtect</a> function to grant <b>PAGE_EXECUTE</b> access. To free the memory, use the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalfree">GlobalFree</a> function. It is not safe to free memory allocated with <b>GlobalAlloc</b> using <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-localfree">LocalFree</a>.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalalloc#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.1.2600")]
internal static winmdroot.Foundation.HGLOBAL GlobalAlloc(winmdroot.System.Memory.GLOBAL_ALLOC_FLAGS uFlags, nuint dwBytes)
{
Marshal.SetLastSystemError(0);
winmdroot.Foundation.HGLOBAL __retVal = LocalExternFunction(uFlags, dwBytes);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "GlobalAlloc"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern winmdroot.Foundation.HGLOBAL LocalExternFunction(winmdroot.System.Memory.GLOBAL_ALLOC_FLAGS uFlags, nuint dwBytes);
}
/// <summary>Locks a global memory object and returns a pointer to the first byte of the object's memory block.</summary>
/// <param name="hMem">
/// <para>A handle to the global memory object. This handle is returned by either the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalalloc">GlobalAlloc</a> or <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalrealloc">GlobalReAlloc</a> function.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globallock#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is a pointer to the first byte of the memory block. If the function fails, the return value is <b>NULL</b>. To get extended error information, call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>.</para>
/// </returns>
/// <remarks>
/// <para>The internal data structures for each memory object include a lock count that is initially zero. For movable memory objects, <b>GlobalLock</b> increments the count by one, and the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalunlock">GlobalUnlock</a> function decrements the count by one. Each successful call that a process makes to <b>GlobalLock</b> for an object must be matched by a corresponding call to <b>GlobalUnlock</b>. Locked memory will not be moved or discarded, unless the memory object is reallocated by using the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalrealloc">GlobalReAlloc</a> function. The memory block of a locked memory object remains locked until its lock count is decremented to zero, at which time it can be moved or discarded. Memory objects allocated with <b>GMEM_FIXED</b> always have a lock count of zero. For these objects, the value of the returned pointer is equal to the value of the specified handle. If the specified memory block has been discarded or if the memory block has a zero-byte size, this function returns <b>NULL</b>. Discarded objects always have a lock count of zero.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globallock#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.1.2600")]
internal static unsafe void* GlobalLock(winmdroot.Foundation.HGLOBAL hMem)
{
Marshal.SetLastSystemError(0);
void* __retVal = LocalExternFunction(hMem);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "GlobalLock"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern unsafe void* LocalExternFunction(winmdroot.Foundation.HGLOBAL hMem);
}
/// <summary>Changes the size or attributes of a specified global memory object. The size can increase or decrease.</summary>
/// <param name="hMem">
/// <para>A handle to the global memory object to be reallocated. This handle is returned by either the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalalloc">GlobalAlloc</a> or <b>GlobalReAlloc</b> function.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalrealloc#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <param name="dwBytes">The new size of the memory block, in bytes. If <i>uFlags</i> specifies <b>GMEM_MODIFY</b>, this parameter is ignored.</param>
/// <param name="uFlags">
/// <para>The reallocation options. If <b>GMEM_MODIFY</b> is specified, the function modifies the attributes of the memory object only (the <i>dwBytes</i> parameter is ignored.) Otherwise, the function reallocates the memory object. You can optionally combine <b>GMEM_MODIFY</b> with the following value. </para>
/// <para>This doc was truncated.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalrealloc#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is a handle to the reallocated memory object. If the function fails, the return value is <b>NULL</b>. To get extended error information, call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>.</para>
/// </returns>
/// <remarks>
/// <para>If <b>GlobalReAlloc</b> reallocates a movable object, the return value is a handle to the memory object. To convert the handle to a pointer, use the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globallock">GlobalLock</a> function. If <b>GlobalReAlloc</b> reallocates a fixed object, the value of the handle returned is the address of the first byte of the memory block. To access the memory, a process can simply cast the return value to a pointer. If <b>GlobalReAlloc</b> fails, the original memory is not freed, and the original handle and pointer are still valid.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalrealloc#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.1.2600")]
internal static winmdroot.Foundation.HGLOBAL GlobalReAlloc(winmdroot.Foundation.HGLOBAL hMem, nuint dwBytes, uint uFlags)
{
Marshal.SetLastSystemError(0);
winmdroot.Foundation.HGLOBAL __retVal = LocalExternFunction(hMem, dwBytes, uFlags);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "GlobalReAlloc"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern winmdroot.Foundation.HGLOBAL LocalExternFunction(winmdroot.Foundation.HGLOBAL hMem, nuint dwBytes, uint uFlags);
}
/// <summary>Retrieves the current size of the specified global memory object, in bytes.</summary>
/// <param name="hMem">
/// <para>A handle to the global memory object. This handle is returned by either the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalalloc">GlobalAlloc</a> or <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalrealloc">GlobalReAlloc</a> function.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalsize#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is the size of the specified global memory object, in bytes. If the specified handle is not valid or if the object has been discarded, the return value is zero. To get extended error information, call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>.</para>
/// </returns>
/// <remarks>
/// <para>The size of a memory block may be larger than the size requested when the memory was allocated. To verify that the specified object's memory block has not been discarded, use the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalflags">GlobalFlags</a> function before calling <b>GlobalSize</b>.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalsize#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.1.2600")]
internal static nuint GlobalSize(winmdroot.Foundation.HGLOBAL hMem)
{
Marshal.SetLastSystemError(0);
nuint __retVal = LocalExternFunction(hMem);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "GlobalSize"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern nuint LocalExternFunction(winmdroot.Foundation.HGLOBAL hMem);
}
/// <summary>Decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE.</summary>
/// <param name="hMem">
/// <para>A handle to the global memory object. This handle is returned by either the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalalloc">GlobalAlloc</a> or <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalrealloc">GlobalReAlloc</a> function.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalunlock#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <returns>
/// <para>If the memory object is still locked after decrementing the lock count, the return value is a nonzero value. If the memory object is unlocked after decrementing the lock count, the function returns zero and <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a> returns <b>NO_ERROR</b>. If the function fails, the return value is zero and <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a> returns a value other than <b>NO_ERROR</b>.</para>
/// </returns>
/// <remarks>
/// <para>The internal data structures for each memory object include a lock count that is initially zero. For movable memory objects, the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globallock">GlobalLock</a> function increments the count by one, and <b>GlobalUnlock</b> decrements the count by one. For each call that a process makes to <b>GlobalLock</b> for an object, it must eventually call <b>GlobalUnlock</b>. Locked memory will not be moved or discarded, unless the memory object is reallocated by using the <a href="https://docs.microsoft.com/windows/desktop/api/winbase/nf-winbase-globalrealloc">GlobalReAlloc</a> function. The memory block of a locked memory object remains locked until its lock count is decremented to zero, at which time it can be moved or discarded. Memory objects allocated with <b>GMEM_FIXED</b> always have a lock count of zero. If the specified memory block is fixed memory, this function returns <b>TRUE</b>. If the memory object is already unlocked, <b>GlobalUnlock</b> returns <b>FALSE</b> and <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a> reports <b>ERROR_NOT_LOCKED</b>. A process should not rely on the return value to determine the number of times it must subsequently call <b>GlobalUnlock</b> for a memory object.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winbase/nf-winbase-globalunlock#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.1.2600")]
internal static winmdroot.Foundation.BOOL GlobalUnlock(winmdroot.Foundation.HGLOBAL hMem)
{
Marshal.SetLastSystemError(0);
winmdroot.Foundation.BOOL __retVal = LocalExternFunction(hMem);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "GlobalUnlock"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern winmdroot.Foundation.BOOL LocalExternFunction(winmdroot.Foundation.HGLOBAL hMem);
}
/// <summary>Frees the loaded dynamic-link library (DLL) module and, if necessary, decrements its reference count.</summary>
/// <param name="hLibModule">
/// <para>A handle to the loaded library module. The <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibrarya">LoadLibrary</a>, <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibraryexa">LoadLibraryEx</a>, <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-getmodulehandlea">GetModuleHandle</a>, or <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-getmodulehandleexa">GetModuleHandleEx</a> function returns this handle.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/libloaderapi/nf-libloaderapi-freelibrary#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call the <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a> function.</para>
/// </returns>
/// <remarks>
/// <para>The system maintains a per-process reference count for each loaded module. A module that was loaded at process initialization due to load-time dynamic linking has a reference count of one. The reference count for a module is incremented each time the module is loaded by a call to <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibrarya">LoadLibrary</a>. The reference count is also incremented by a call to <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibraryexa">LoadLibraryEx</a> unless the module is being loaded for the first time and is being loaded as a data or image file. The reference count is decremented each time the <b>FreeLibrary</b> or <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-freelibraryandexitthread">FreeLibraryAndExitThread</a> function is called for the module. When a module's reference count reaches zero or the process terminates, the system unloads the module from the address space of the process. Before unloading a library module, the system enables the module to detach from the process by calling the module's <a href="https://docs.microsoft.com/windows/desktop/Dlls/dllmain">DllMain</a> function, if it has one, with the DLL_PROCESS_DETACH value. Doing so gives the library module an opportunity to clean up resources allocated on behalf of the current process. After the entry-point function returns, the library module is removed from the address space of the current process. It is not safe to call <b>FreeLibrary</b> from <a href="https://docs.microsoft.com/windows/desktop/Dlls/dllmain">DllMain</a>. For more information, see the Remarks section in <a href="https://docs.microsoft.com/windows/desktop/Dlls/dllmain">DllMain</a>. Calling <b>FreeLibrary</b> does not affect other processes that are using the same module. Use caution when calling <b>FreeLibrary</b> with a handle returned by <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-getmodulehandlea">GetModuleHandle</a>. The <b>GetModuleHandle</b> function does not increment a module's reference count, so passing this handle to <b>FreeLibrary</b> can cause a module to be unloaded prematurely. A thread that must unload the DLL in which it is executing and then terminate itself should call <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-freelibraryandexitthread">FreeLibraryAndExitThread</a> instead of calling <b>FreeLibrary</b> and <b>ExitThread</b> separately. Otherwise, a race condition can occur. For details, see the Remarks section of <a href="https://docs.microsoft.com/windows/desktop/api/libloaderapi/nf-libloaderapi-freelibraryandexitthread">FreeLibraryAndExitThread</a>.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/libloaderapi/nf-libloaderapi-freelibrary#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.1.2600")]
internal static winmdroot.Foundation.BOOL FreeLibrary(winmdroot.Foundation.HMODULE hLibModule)
{
Marshal.SetLastSystemError(0);
winmdroot.Foundation.BOOL __retVal = LocalExternFunction(hLibModule);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "FreeLibrary"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern winmdroot.Foundation.BOOL LocalExternFunction(winmdroot.Foundation.HMODULE hLibModule);
}
/// <inheritdoc cref="MultiByteToWideChar(uint, winmdroot.Globalization.MULTI_BYTE_TO_WIDE_CHAR_FLAGS, winmdroot.Foundation.PCSTR, int, winmdroot.Foundation.PWSTR, int)"/>
[SupportedOSPlatform("windows5.0")]
internal static unsafe int MultiByteToWideChar(uint CodePage, winmdroot.Globalization.MULTI_BYTE_TO_WIDE_CHAR_FLAGS dwFlags, string lpMultiByteStr, int cbMultiByte, winmdroot.Foundation.PWSTR lpWideCharStr, int cchWideChar)
{
fixed (byte* lpMultiByteStrLocal = lpMultiByteStr is object ? global::System.Text.Encoding.Default.GetBytes(lpMultiByteStr) : null)
{
int __result = PInvokeCore.MultiByteToWideChar(CodePage, dwFlags, new winmdroot.Foundation.PCSTR (lpMultiByteStrLocal), cbMultiByte, lpWideCharStr, cchWideChar);
return __result;
}
}
/// <summary>Maps a character string to a UTF-16 (wide character) string.</summary>
/// <param name="CodePage">
/// <para>Code page to use in performing the conversion. This parameter can be set to the value of any code page that is installed or available in the operating system. For a list of code pages, see <a href="https://docs.microsoft.com/windows/desktop/Intl/code-page-identifiers">Code Page Identifiers</a>. Your application can also specify one of the values shown in the following table. </para>
/// <para>This doc was truncated.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <param name="dwFlags"></param>
/// <param name="lpMultiByteStr">Pointer to the character string to convert.</param>
/// <param name="cbMultiByte">
/// <para>Size, in bytes, of the string indicated by the <i>lpMultiByteStr</i> parameter. Alternatively, this parameter can be set to -1 if the string is null-terminated. Note that, if <i>cbMultiByte</i> is 0, the function fails. If this parameter is -1, the function processes the entire input string, including the terminating null character. Therefore, the resulting Unicode string has a terminating null character, and the length returned by the function includes this character. If this parameter is set to a positive integer, the function processes exactly the specified number of bytes. If the provided size does not include a terminating null character, the resulting Unicode string is not null-terminated, and the returned length does not include this character.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <param name="lpWideCharStr">Pointer to a buffer that receives the converted string.</param>
/// <param name="cchWideChar">Size, in characters, of the buffer indicated by <i>lpWideCharStr</i>. If this value is 0, the function returns the required buffer size, in characters, including any terminating null character, and makes no use of the <i>lpWideCharStr</i> buffer.</param>
/// <returns>
/// <para>Returns the number of characters written to the buffer indicated by <i>lpWideCharStr</i> if successful. If the function succeeds and <i>cchWideChar</i> is 0, the return value is the required size, in characters, for the buffer indicated by <i>lpWideCharStr</i>. Also see <i>dwFlags</i> for info about how the MB_ERR_INVALID_CHARS flag affects the return value when invalid sequences are input. The function returns 0 if it does not succeed. To get extended error information, the application can call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>, which can return one of the following error codes: </para>
/// <para>This doc was truncated.</para>
/// </returns>
/// <remarks>
/// <para>The default behavior of this function is to translate to a precomposed form of the input character string. If a precomposed form does not exist, the function attempts to translate to a composite form. The use of the MB_PRECOMPOSED flag has very little effect on most code pages because most input data is composed already. Consider calling <a href="https://docs.microsoft.com/windows/desktop/api/winnls/nf-winnls-normalizestring">NormalizeString</a> after converting with <b>MultiByteToWideChar</b>. <b>NormalizeString</b> provides more accurate, standard, and consistent data, and can also be faster. Note that for the <a href="https://docs.microsoft.com/windows/desktop/api/winnls/ne-winnls-norm_form">NORM_FORM</a> enumeration being passed to <b>NormalizeString</b>, NormalizationC corresponds to MB_PRECOMPOSED and NormalizationD corresponds to MB_COMPOSITE. As mentioned in the caution above, the output buffer can easily be overrun if this function is not first called with <i>cchWideChar</i> set to 0 in order to obtain the required size. If the MB_COMPOSITE flag is used, the output can be three or more characters long for each input character. The <i>lpMultiByteStr</i> and <i>lpWideCharStr</i> pointers must not be the same. If they are the same, the function fails, and <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a> returns the value ERROR_INVALID_PARAMETER. <b>MultiByteToWideChar</b> does not null-terminate an output string if the input string length is explicitly specified without a terminating null character. To null-terminate an output string for this function, the application should pass in -1 or explicitly count the terminating null character for the input string. The function fails if MB_ERR_INVALID_CHARS is set and an invalid character is encountered in the source string. An invalid character is one of the following: </para>
/// <para>This doc was truncated.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.0")]
internal static int MultiByteToWideChar(uint CodePage, winmdroot.Globalization.MULTI_BYTE_TO_WIDE_CHAR_FLAGS dwFlags, winmdroot.Foundation.PCSTR lpMultiByteStr, int cbMultiByte, winmdroot.Foundation.PWSTR lpWideCharStr, int cchWideChar)
{
Marshal.SetLastSystemError(0);
int __retVal = LocalExternFunction(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, lpWideCharStr, cchWideChar);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "MultiByteToWideChar"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern int LocalExternFunction(uint CodePage, winmdroot.Globalization.MULTI_BYTE_TO_WIDE_CHAR_FLAGS dwFlags, winmdroot.Foundation.PCSTR lpMultiByteStr, int cbMultiByte, winmdroot.Foundation.PWSTR lpWideCharStr, int cchWideChar);
}
/// <inheritdoc cref="WideCharToMultiByte(uint, uint, winmdroot.Foundation.PCWSTR, int, winmdroot.Foundation.PSTR, int, winmdroot.Foundation.PCSTR, winmdroot.Foundation.BOOL*)"/>
[SupportedOSPlatform("windows5.0")]
internal static unsafe int WideCharToMultiByte(uint CodePage, uint dwFlags, string lpWideCharStr, int cchWideChar, winmdroot.Foundation.PSTR lpMultiByteStr, int cbMultiByte, string lpDefaultChar, winmdroot.Foundation.BOOL* lpUsedDefaultChar)
{
fixed (byte* lpDefaultCharLocal = lpDefaultChar is object ? global::System.Text.Encoding.Default.GetBytes(lpDefaultChar) : null)
{
fixed (char* lpWideCharStrLocal = lpWideCharStr)
{
int __result = PInvokeCore.WideCharToMultiByte(CodePage, dwFlags, lpWideCharStrLocal, cchWideChar, lpMultiByteStr, cbMultiByte, new winmdroot.Foundation.PCSTR (lpDefaultCharLocal), lpUsedDefaultChar);
return __result;
}
}
}
/// <summary>Maps a UTF-16 (wide character) string to a new character string.</summary>
/// <param name="CodePage">
/// <para>Code page to use in performing the conversion. This parameter can be set to the value of any code page that is installed or available in the operating system. For a list of code pages, see <a href="https://docs.microsoft.com/windows/desktop/Intl/code-page-identifiers">Code Page Identifiers</a>. Your application can also specify one of the values shown in the following table. </para>
/// <para>This doc was truncated.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <param name="dwFlags"></param>
/// <param name="lpWideCharStr">Pointer to the Unicode string to convert.</param>
/// <param name="cchWideChar">
/// <para>Size, in characters, of the string indicated by <i>lpWideCharStr</i>. Alternatively, this parameter can be set to -1 if the string is null-terminated. If <i>cchWideChar</i> is set to 0, the function fails. If this parameter is -1, the function processes the entire input string, including the terminating null character. Therefore, the resulting character string has a terminating null character, and the length returned by the function includes this character. If this parameter is set to a positive integer, the function processes exactly the specified number of characters. If the provided size does not include a terminating null character, the resulting character string is not null-terminated, and the returned length does not include this character.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <param name="lpMultiByteStr">Pointer to a buffer that receives the converted string.</param>
/// <param name="cbMultiByte">Size, in bytes, of the buffer indicated by <i>lpMultiByteStr</i>. If this value is 0, the function returns the required buffer size, in bytes, including any terminating null character, and makes no use of the <i>lpMultiByteStr</i> buffer.</param>
/// <param name="lpDefaultChar">
/// <para>Pointer to the character to use if a character cannot be represented in the specified code page. The application sets this parameter to <b>NULL</b> if the function is to use a system default value. To obtain the system default character, the application can call the <a href="https://docs.microsoft.com/windows/desktop/api/winnls/nf-winnls-getcpinfo">GetCPInfo</a> or <a href="https://docs.microsoft.com/windows/desktop/api/winnls/nf-winnls-getcpinfoexa">GetCPInfoEx</a> function. For the CP_UTF7 and CP_UTF8 settings for <i>CodePage</i>, this parameter must be set to <b>NULL</b>. Otherwise, the function fails with ERROR_INVALID_PARAMETER.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <param name="lpUsedDefaultChar">
/// <para>Pointer to a flag that indicates if the function has used a default character in the conversion. The flag is set to <b>TRUE</b> if one or more characters in the source string cannot be represented in the specified code page. Otherwise, the flag is set to <b>FALSE</b>. This parameter can be set to <b>NULL</b>. For the CP_UTF7 and CP_UTF8 settings for <i>CodePage</i>, this parameter must be set to <b>NULL</b>. Otherwise, the function fails with ERROR_INVALID_PARAMETER.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte#parameters">Read more on docs.microsoft.com</see>.</para>
/// </param>
/// <returns>
/// <para>If successful, returns the number of bytes written to the buffer pointed to by <i>lpMultiByteStr</i>. If the function succeeds and <i>cbMultiByte</i> is 0, the return value is the required size, in bytes, for the buffer indicated by <i>lpMultiByteStr</i>. Also see <i>dwFlags</i> for info about how the WC_ERR_INVALID_CHARS flag affects the return value when invalid sequences are input. The function returns 0 if it does not succeed. To get extended error information, the application can call <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a>, which can return one of the following error codes: </para>
/// <para>This doc was truncated.</para>
/// </returns>
/// <remarks>
/// <para>The <i>lpMultiByteStr</i> and <i>lpWideCharStr</i> pointers must not be the same. If they are the same, the function fails, and <a href="https://docs.microsoft.com/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror">GetLastError</a> returns ERROR_INVALID_PARAMETER. <b>WideCharToMultiByte</b> does not null-terminate an output string if the input string length is explicitly specified without a terminating null character. To null-terminate an output string for this function, the application should pass in -1 or explicitly count the terminating null character for the input string. If <i>cbMultiByte</i> is less than <i>cchWideChar</i>, this function writes the number of characters specified by <i>cbMultiByte</i> to the buffer indicated by <i>lpMultiByteStr</i>. However, if <i>CodePage</i> is set to CP_SYMBOL and <i>cbMultiByte</i> is less than <i>cchWideChar,</i> the function writes no characters to <i>lpMultiByteStr</i>. The <b>WideCharToMultiByte</b> function operates most efficiently when both <i>lpDefaultChar</i> and <i>lpUsedDefaultChar</i> are set to <b>NULL</b>. The following table shows the behavior of the function for the four possible combinations of these parameters. </para>
/// <para>This doc was truncated.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte#">Read more on docs.microsoft.com</see>.</para>
/// </remarks>
[SupportedOSPlatform("windows5.0")]
internal static unsafe int WideCharToMultiByte(uint CodePage, uint dwFlags, winmdroot.Foundation.PCWSTR lpWideCharStr, int cchWideChar, winmdroot.Foundation.PSTR lpMultiByteStr, int cbMultiByte, winmdroot.Foundation.PCSTR lpDefaultChar, [Optional] winmdroot.Foundation.BOOL* lpUsedDefaultChar)
{
Marshal.SetLastSystemError(0);
int __retVal = LocalExternFunction(CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar);
Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
return __retVal;
[DllImport("KERNEL32.dll", ExactSpelling = true, EntryPoint = "WideCharToMultiByte"),DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern unsafe int LocalExternFunction(uint CodePage, uint dwFlags, winmdroot.Foundation.PCWSTR lpWideCharStr, int cchWideChar, winmdroot.Foundation.PSTR lpMultiByteStr, int cbMultiByte, winmdroot.Foundation.PCSTR lpDefaultChar, [Optional] winmdroot.Foundation.BOOL* lpUsedDefaultChar);
}
}
}
|