Example #1
0
        private void Load(string filePath)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("Safe file handler was closed");
            }

            if (filePath == null || filePath.Length == 0)
            {
                throw new FileNotFoundException("specified file was not founf");
            }

            ptr        = FileNativeMethods.CreateFile(filePath, GENERIC_READ | GENERIC_WRITE, 0, IntPtr.Zero, CREATE_NEW, 0, IntPtr.Zero);
            safeHandle = new SafeFileHandle(ptr, true);

            if (safeHandle.IsInvalid)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
        }
Example #2
0
        public void Write(StringBuilder text)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("Safe file handler was closed");
            }

            var natOverlap = new NativeOverlapped {
                OffsetLow = (int)0
            };
            uint writenSize;
            var  isSuccess = FileNativeMethods.WriteFile(
                ptr,
                text,
                (uint)Encoding.Unicode.GetByteCount(text.ToString()),
                out writenSize,
                ref natOverlap);

            if (!isSuccess)
            {
                Console.WriteLine("error");
            }
        }