C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[73698] Rad Studio C++ 10.1 Berlin에서 CreateFile 에러
imbklee [imbklee] 4848 읽음    2016-07-05 05:21
FileHandle.zip 2MB BCC6와 10.1Berlin 용 소스 및 실행파일 압축
첨부한 파일은 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");
    }
}
//---------------------------------------------------------------------------


+ -

관련 글 리스트
73698 Rad Studio C++ 10.1 Berlin에서 CreateFile 에러 imbklee 4848 2016/07/05
73699     [답변] 문자열 형식 정성훈.해미 4440 2016/07/05
73700         Re:[답변] 문자열 형식 imbklee 4730 2016/07/05
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.