Beispiel #1
0
        public void MarshalManaged(TCustomMarshaler info, object managed)
        {
            var native = info.MarshalManagedToNative(managed);

            MarshalInitialization <IntPtr, object> .ObjectInitialized(native);

            info.CleanUpNativeData(native);
        }
Beispiel #2
0
        public void MarshalNative(TCustomMarshaler info, IntPtr native)
        {
            var managed = info.MarshalNativeToManaged(native);

            MarshalInitialization <IntPtr, object> .ObjectInitialized(managed);

            info.CleanUpManagedData(managed);
        }
Beispiel #3
0
        public override void MarshalNative(StringMarshalerInfo info, IntPtr native)
        {
            string res = null;

            if (native != IntPtr.Zero)
            {
                res = GetEncoding(info).GetString((byte *)native, GetStringLength(native));
            }
            MarshalInitialization <IntPtr, string> .ObjectInitialized(res);
        }
Beispiel #4
0
        public override void MarshalManaged(StringMarshalerInfo info, string managed)
        {
            var data = new byte[(info.UnmanagedType == UnmanagedType.LPWStr ? 2 : 1) * managed.Length + 1];
            var text = managed.AsSpan();

            fixed(char *inputPtr = &text.GetPinnableReference())
            fixed(byte *dataPtr = data)
            {
                GetEncoding(info).GetBytes(inputPtr, text.Length, dataPtr, data.Length);
                MarshalInitialization <IntPtr, string> .ObjectInitialized((IntPtr)dataPtr);
            }
        }