//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	HANDLE hFile;
	DWORD dFileSize, dBytesRead;
	BOOL bResult;

	__try
	{
		hFile = CreateFile("c:\\windows\\win.ini",   // for BCC6
		//hFile = CreateFile((const wchar_t *)"c:\\windows\\win.ini",   // for 10.1 Berlin
							GENERIC_READ,
							0,
							NULL,
							OPEN_EXISTING,
							FILE_ATTRIBUTE_NORMAL,
							NULL);

		if( hFile == INVALID_HANDLE_VALUE )
		{
			ShowMessage("There was a problem opening the file");
			return;
		}

		dFileSize = GetFileSize(hFile, NULL);
		if( dFileSize == 0xFFFFFFFF )
		{
			ShowMessage("Invalid file size");
			return;
		}

		char *p = new char [16086381];
		bResult = ReadFile(hFile, p, dFileSize, &dBytesRead, NULL);
		delete p;

		if( bResult == FALSE )
		{
			ShowMessage("The file could not be read");
			return;
		}
	}
	__finally
	{
		if( hFile != INVALID_HANDLE_VALUE )
        {
			CloseHandle(hFile);
			ShowMessage("Success !!");
		}
        else
			ShowMessage("INVALID_HANDLE_VALUE");
	}
}
//---------------------------------------------------------------------------

