static void Main(string[] args) { using (FileWritter writter = new FileWritter("test.txt")) { string textToWrite = "Test text"; writter.Write(textToWrite); } }
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); }
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); }