1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
   | #include <iostream>
#include <windows.h>
using namespace std;
 
int main() {
	const char* file="truc.txt";
	HANDLE h;
	DWORD *d= new DWORD();
	HANDLE stdout;
	DWORD *o= new DWORD();
	char text[9]= "whatever";
	char outtext[9];
 
	stdout = GetStdHandle(STD_OUTPUT_HANDLE);
 
	h=CreateFile(file,
			GENERIC_WRITE,
			FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE,
			NULL,
			CREATE_ALWAYS,
			FILE_ATTRIBUTE_NORMAL,
			NULL);
	if (h == INVALID_HANDLE_VALUE)
		cout << "File not created" << endl;
	else
	{
		GetHandleInformation(h,d);
		WriteFile(h,text,strlen(text),o,NULL);
		//WriteFile(stdout,d,10,o,NULL);
		ReadFile(h,outtext,strlen(text),o,NULL);
 
		stdout << outtext << endl;
	}
 
	return 0;
} | 
Partager