|
첨부한 파일은 CreateFile 테스트프로그램으로 다른분이 올려놓은 것을 아주 약간 수정한 것으로, 압축을 풀면 2개의 디렉토리에 BCC6 버전과 Rad Studio C++ 10.1 Berlin 버전의 소스파일과 프로젝트파일 및 실행파일이 들어있습니다.
2개의 버전별 디렉토리에 있는 Project1.exe을 실행해 보면,
BCC6 버전은 잘 작동되나 Rad Studio C++ 10.1 Berlin 버전은 CreateFile에서 HANDLE을 얻어오지 못하는 것을 알 수 있습니다.
첨부자료에 들어있는 Rad Studio C++ 10.1 Berlin 버전의 Unit1.cpp는 아래와 같은데,
BCC6에서 컴파일하려면 다음 2줄만 고치면 됩니다.
hFile = CreateFile("c:\\windows\\win.ini", // for BCC6
//hFile = CreateFile((const wchar_t *)"c:\\windows\\win.ini", // for 10.1 Berlin
제가 굳이 CreateFile로 HANDLE을 얻으려는 이유는 메모리맵드파일로 대용량파일을 제어하기 위해서 입니다.
제가 무엇을 잘못했는지 알려주시면 갑사하겠습니다.
//---------------------------------------------------------------------------
#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");
}
}
//---------------------------------------------------------------------------
|