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); } }
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); }
public unsafe static IntPtr AllocZeroBString(int length) { return(BStringVTable.Create(length)); }