in windows

Windows API: WriteFile

This is the start of me learning the windows API do do various diffrent tasks.

#include <windows.h>
#include <tchar.h>
#include <stdio.h>



int main() {

	HANDLE myFile;
	myFile = CreateFile(_T("C://Users//rob//Dropbox//testfile.txt"),
						GENERIC_READ | GENERIC_WRITE,
						0,
						NULL,
						CREATE_ALWAYS,
						FILE_ATTRIBUTE_NORMAL,
						NULL
	);

	if (myFile == INVALID_HANDLE_VALUE) {

		printf("Error the file does not exist %u\n", GetLastError());
		
	}
	else {
		printf("Yay we opened a file and have a handle to it %p\n", myFile);
	}

	char testline [] = "This is a test string to write to the file\n";
	BOOL write1= FALSE;
	DWORD byteswritten = 0;
	write1 = WriteFile(myFile,
					   testline,
						sizeof testline,
						&byteswritten,
						NULL
		);

	if (write1 == FALSE) {

		printf("Failed , %x", GetLastError());
	}
	else {

		printf("Success we wrote to the file\n");
	}
}