示例#1
0
        public unsafe static void FreeBString(IntPtr ptr)
        {
            var releaseDelegate = DelegateRuntimeInfo <DestructIndirect> .RcfpwDelegate;

            if (ptr == (IntPtr)0)
            {
                return;
            }

            IntPtr *vtable = *((IntPtr **)ptr);

            // call destructor
            IntPtr releaseFunctionPtr = vtable[0];

            if (releaseFunctionPtr == BStringVTable.vtable[0])
            {
                // calli on a function ptr created by GetFunctionPointerForDelegate crashes
                // on .NET Core for some reason
                BStringVTable.BStringDestructor(ptr);
            }
            else
            {
                releaseDelegate(releaseFunctionPtr, ptr);
            }
        }
示例#2
0
        public unsafe static IntPtr AllocBString(string str)
        {
            if (str == null)
            {
                return(IntPtr.Zero);
            }
            byte[] bytes   = System.Text.Encoding.UTF8.GetBytes(str);
            var    bstr    = BStringVTable.Create(bytes.Length);
            byte * dataptr = GetBStringDataPtr(bstr);

            Marshal.Copy(bytes, 0, (IntPtr)dataptr, bytes.Length);
            return(bstr);
        }
示例#3
0
 public unsafe static IntPtr AllocZeroBString(int length)
 {
     return(BStringVTable.Create(length));
 }