示例#1
0
        private static Result CloseImpl(IntPtr thisPtr, IntPtr pData)
        {
            try
            {
                IncludeShadow shadow   = ToShadow <IncludeShadow>(thisPtr);
                Include       callback = (Include)shadow.Callback;

                if (shadow._frames.TryGetValue(pData, out Frame frame))
                {
                    shadow._frames.Remove(pData);
                    callback.Close(frame.Stream);
                    frame.Dispose();
                }

                return(Result.Ok);
            }
            catch (SharpGenException exception)
            {
                return(exception.ResultCode.Code);
            }
            catch (Exception)
            {
                return(Result.Fail);
            }
        }
    private static unsafe partial int OpenImpl_(IntPtr thisObject, int _includeType, void *_fileName, void *_parentData, void *_data, void *_bytes)
    {
        IncludeShadow shadow   = CppObjectShadow.ToAnyShadow <IncludeShadow>(thisObject);
        Include       callback = shadow.ToCallback <Include>();

        try
        {
            IncludeType includeType = (IncludeType)_includeType;
            IntPtr      parentData  = (IntPtr)_parentData;
            ref IntPtr  data        = ref Unsafe.AsRef <IntPtr>(_data);
            ref int     bytes       = ref Unsafe.AsRef <int>(_bytes);
示例#3
0
        private static Result OpenImpl(IntPtr thisPtr, IncludeType includeType, IntPtr fileNameRef, IntPtr pParentData, ref IntPtr dataRef, ref int bytesRef)
        {
            try
            {
                IncludeShadow shadow   = ToShadow <IncludeShadow>(thisPtr);
                Include       callback = (Include)shadow.Callback;

                Stream?stream       = null;
                Stream?parentStream = null;

                if (shadow._frames.ContainsKey(pParentData))
                {
                    parentStream = shadow._frames[pParentData].Stream;
                }

                stream = callback.Open(includeType, Marshal.PtrToStringAnsi(fileNameRef), parentStream);
                if (stream == null)
                {
                    return(Result.Fail);
                }

                GCHandle handle;

                //if (stream is DataStream)
                //{
                //    // Magic shortcut if we happen to get a DataStream
                //    var data = (DataStream)stream;
                //    dataRef = data.PositionPointer;
                //    bytesRef = (int)(data.Length - data.Position);
                //    handle = new GCHandle();
                //}
                //else
                {
                    // Read the stream into a byte array and pin it
                    byte[] data = ReadStream(stream);
                    handle   = GCHandle.Alloc(data, GCHandleType.Pinned);
                    dataRef  = handle.AddrOfPinnedObject();
                    bytesRef = data.Length;
                }

                shadow._frames.Add(dataRef, new Frame(stream, handle));

                return(Result.Ok);
            }
            catch (SharpGenException exception)
            {
                return(exception.ResultCode.Code);
            }
            catch (Exception)
            {
                return(Result.Fail);
            }
        }