예제 #1
0
 static void Main(string[] args)
 {
     using (FileWritter writter = new FileWritter("test.txt"))
     {
         string textToWrite = "Test text";
         writter.Write(textToWrite);
     }
 }
예제 #2
0
        private IntPtr Open(string filePath)
        {
            IntPtr fileHandle = FileWritter.CreateFile(filePath, DesiredAccess.GENERIC_WRITE, 0, 0, CreationDisposition.OPEN_ALWAYS, 0, 0);

            if (fileHandle == IntPtr.Zero)
            {
                throw new Exception($"Cannot creat {filePath}");
            }

            return(fileHandle);
        }
예제 #3
0
        public uint Write(byte[] bytesToWrite, uint bytesToWriteCount)
        {
            if (this.fileHandle == IntPtr.Zero)
            {
                this.fileHandle = this.Open(this.filepath);
            }

            uint writtenBytesCount = 0;

            if (!FileWritter.WriteFile(this.fileHandle, bytesToWrite, bytesToWriteCount, out writtenBytesCount, IntPtr.Zero))
            {
                throw new Exception($"Could not wirte to file: {this.filepath}");
            }
            return(writtenBytesCount);
        }