示例#1
0
        private static IntPtr ConvertStringToNative(string pManagedHome, int dwFlags)
        {
            IntPtr pNativeHome;

            // IsIn, IsOut are ignored for strings - they're always in-only
            if (IsAnsi(dwFlags))
            {
                // marshal the object as Ansi string (UnmanagedType.LPStr)
                pNativeHome = CSTRMarshaler.ConvertToNative(
                    dwFlags & 0xFFFF, // (throw on unmappable char << 8 | best fit)
                    pManagedHome,     //
                    IntPtr.Zero);     // unmanaged buffer will be allocated
            }
            else
            {
                // marshal the object as Unicode string (UnmanagedType.LPWStr)
                int allocSize = (pManagedHome.Length + 1) * 2;
                pNativeHome = Marshal.AllocCoTaskMem(allocSize);
                unsafe
                {
                    Buffer.Memmove(ref *(char *)pNativeHome, ref pManagedHome.GetRawStringData(), (nuint)pManagedHome.Length + 1);
                }
            }

            return(pNativeHome);
        }
        private static IntPtr ConvertStringToNative(string pManagedHome, int dwFlags)
        {
            if (IsAnsi(dwFlags))
            {
                return(CSTRMarshaler.ConvertToNative(dwFlags & 0xffff, pManagedHome, IntPtr.Zero));
            }
            System.StubHelpers.StubHelpers.CheckStringLength(pManagedHome.Length);
            int    cb   = (pManagedHome.Length + 1) * 2;
            IntPtr dest = Marshal.AllocCoTaskMem(cb);

            string.InternalCopy(pManagedHome, dest, cb);
            return(dest);
        }
        private static IntPtr ConvertStringToNative(string pManagedHome, int dwFlags)
        {
            IntPtr intPtr;

            if (AsAnyMarshaler.IsAnsi(dwFlags))
            {
                intPtr = CSTRMarshaler.ConvertToNative(dwFlags & 65535, pManagedHome, IntPtr.Zero);
            }
            else
            {
                StubHelpers.CheckStringLength(pManagedHome.Length);
                int num = (pManagedHome.Length + 1) * 2;
                intPtr = Marshal.AllocCoTaskMem(num);
                string.InternalCopy(pManagedHome, intPtr, num);
            }
            return(intPtr);
        }
示例#4
0
        private static IntPtr ConvertStringToNative(string pManagedHome, int dwFlags)
        {
            IntPtr dest;

            if (AsAnyMarshaler.IsAnsi(dwFlags))
            {
                dest = CSTRMarshaler.ConvertToNative(dwFlags & (int)ushort.MaxValue, pManagedHome, IntPtr.Zero);
            }
            else
            {
                System.StubHelpers.StubHelpers.CheckStringLength(pManagedHome.Length);
                int num = (pManagedHome.Length + 1) * 2;
                dest = Marshal.AllocCoTaskMem(num);
                string.InternalCopy(pManagedHome, dest, num);
            }
            return(dest);
        }