Показать сообщение отдельно

  #13  
Старый 27.08.2008, 23:49
4p3
Участник форума
Регистрация: 18.08.2008
Сообщений: 159
Провел на форуме:
750247

Репутация: 92
Отправить сообщение для 4p3 с помощью ICQ
По умолчанию

Код:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string.h>
#include <windows.h>
#include <cstdlib>

using std::cout;
using std::endl;

int main()
{	
	char *szAntichat = "I love Antichat\0";
	TCHAR *szFile = L"C:\\test.exe";
	DWORD dwWritten = 0;
	
	HANDLE hFile = CreateFile(szFile,
							  GENERIC_WRITE|FILE_APPEND_DATA,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);

	if (hFile == INVALID_HANDLE_VALUE)
	{
		cout << "shit happens" << endl;		
		std::system("pause");
		return 1;
	}
	
	if (SetFilePointer(hFile, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER)
	{
		cout << "never know when it happens again" << endl;
		std::system("pause");
		return 2;
	}	

	if(WriteFile(hFile, szAntichat, strlen(szAntichat), &dwWritten, NULL))
	{
		cout << "Written: 0x";
		for (int i = 0;i < strlen(szAntichat);++i)
		{
			cout << std::hex << szAntichat[i];
		}
	}
	else
		cout << GetLastError() << endl;	
	
	std::system("pause");
	return 0;
}