Example #1
0
        /// <summary>
        /// Creates delegates for the FDI* operation functions.
        /// </summary>
        private void populateDelegates()
        {
            // if a delegate is re-located by a garbage collection, it will not affect
            // the underlaying managed callback, so Alloc is used to add a reference
            // to the delegate, allowing relocation of the delegate, but preventing
            // disposal. Using GCHandle without pinning reduces fragmentation potential
            // of the managed heap.
            _allocDelegate = new CabinetNativeApi.FdiAllocDelegate(CabinetNativeApi.FdiAlloc);
            _fdiAllocHandle = GCHandle.Alloc(_allocDelegate);

            _freeDelegate = new CabinetNativeApi.FdiFreeDelegate(CabinetNativeApi.FdiFree);
            _fdiFreeHandle = GCHandle.Alloc(_freeDelegate);

            _openDelegate = new CabinetNativeApi.FdiOpenDelegate(CabinetNativeApi.FdiOpen);
            _fdiOpenHandle = GCHandle.Alloc(_openDelegate);

            _readDelegate = new CabinetNativeApi.FdiReadDelegate(CabinetNativeApi.FdiRead);
            _fdiReadHandle = GCHandle.Alloc(_readDelegate);

            _writeDelegate = new CabinetNativeApi.FdiWriteDelegate(CabinetNativeApi.FdiWrite);
            _fdiWriteHandle = GCHandle.Alloc(_writeDelegate);

            _closeDelegate = new CabinetNativeApi.FdiCloseDelegate(CabinetNativeApi.FdiClose);
            _fdiCloseHandle = GCHandle.Alloc(_closeDelegate);

            _seekDelegate = new CabinetNativeApi.FdiSeekDelegate(CabinetNativeApi.FdiSeek);
            _fdiSeekHandle = GCHandle.Alloc(_seekDelegate);

            _notifyDelegate = new CabinetNativeApi.FdiNotifyDelegate(CabinetNativeApi.FdiNotify);
            _fdiNotifyHandle = GCHandle.Alloc(_notifyDelegate);
        }