// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.IO;
-using System.Text;
using System.Runtime.InteropServices;
internal partial class Interop
{
internal partial class Kernel32
{
+ [StructLayout(LayoutKind.Sequential)]
internal unsafe struct CPINFO
{
internal int MaxCharSize;
}
[DllImport(Libraries.Kernel32)]
- internal static extern unsafe int GetCPInfo(uint codePage, CPINFO* lpCpInfo);
+ internal static extern unsafe Interop.BOOL GetCPInfo(uint codePage, CPINFO* lpCpInfo);
}
}
{
public static partial class Marshal
{
+ private static int GetSystemMaxDBCSCharSize() => 3;
+
private static bool IsWin32Atom(IntPtr ptr) => false;
internal static unsafe int StringToAnsiString(string s, byte* buffer, int bufferLength, bool bestFit = false, bool throwOnUnmappableChar = false)
{
public static partial class Marshal
{
+ private static unsafe int GetSystemMaxDBCSCharSize()
+ {
+ Interop.Kernel32.CPINFO cpInfo = default;
+
+ if (Interop.Kernel32.GetCPInfo(Interop.Kernel32.CP_ACP, &cpInfo) == Interop.BOOL.FALSE)
+ return 2;
+
+ return cpInfo.MaxCharSize;
+ }
+
// Win32 has the concept of Atoms, where a pointer can either be a pointer
// or an int. If it's less than 64K, this is guaranteed to NOT be a
// pointer since the bottom 64K bytes are reserved in a process' page table.
private const int LMEM_FIXED = 0;
private const int LMEM_MOVEABLE = 2;
- /// <summary>
- /// Helper method to retrieve the system's maximum DBCS character size.
- /// </summary>
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern int GetSystemMaxDBCSCharSize();
-
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int SizeOfHelper(Type t, bool throwIfNotMarshalable);
FCFuncElement("GetLastWin32Error", MarshalNative::GetLastWin32Error)
FCFuncElement("SetLastWin32Error", MarshalNative::SetLastWin32Error)
FCFuncElement("SizeOfHelper", MarshalNative::SizeOfClass)
- FCFuncElement("GetSystemMaxDBCSCharSize", MarshalNative::GetSystemMaxDBCSCharSize)
FCFuncElement("StructureToPtr", MarshalNative::StructureToPtr)
FCFuncElement("PtrToStructureHelper", MarshalNative::PtrToStructureHelper)
FCFuncElement("DestroyStructure", MarshalNative::DestroyStructure)
}
FCIMPLEND
-
-FCIMPL0(UINT32, MarshalNative::GetSystemMaxDBCSCharSize)
-{
- FCALL_CONTRACT;
-
- return GetMaxDBCSCharByteSize();
-}
-FCIMPLEND
-
/************************************************************************
* PInvoke.GetLastWin32Error
*/
static FCDECL3(LPVOID, GetUnmanagedThunkForManagedMethodPtr, LPVOID pfnMethodToWrap, PCCOR_SIGNATURE pbSignature, ULONG cbSignature);
static FCDECL3(LPVOID, GetManagedThunkForUnmanagedMethodPtr, LPVOID pfnMethodToWrap, PCCOR_SIGNATURE pbSignature, ULONG cbSignature);
- static FCDECL0(UINT32, GetSystemMaxDBCSCharSize);
-
static FCDECL2(LPVOID, GCHandleInternalAlloc, Object *obj, int type);
static FCDECL1(VOID, GCHandleInternalFree, OBJECTHANDLE handle);
static FCDECL1(LPVOID, GCHandleInternalGet, OBJECTHANDLE handle);