C++Win32APIReadFile()讀取文件

字號(hào):

直接一起來(lái)看吧:
    #include
    #include
    #include
    #include
    #include
    void main()
    {
    unsigned long lpNumber=0;
    char lpBuffer[50]="";//Examda提示:文件讀取的內(nèi)容
    char IP_path[80]="";
    getcwd(IP_path,80);
    strcat(IP_path,"\\IP.txt");//獲得資源路徑
    HANDLE hFile= CreateFile(IP_path,
    GENERIC_READ,
    0,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    0
    );
    if(hFile==INVALID_HANDLE_VALUE)
    {
    MessageBox(NULL,"創(chuàng)建文件句柄出錯(cuò)","error",MB_OK);
    }
    int filesucc=ReadFile(hFile,
    lpBuffer,
    50,//讀取文件中多少內(nèi)容
    &lpNumber,
    NULL
    );
    CloseHandle(hFile);
    if(filesucc==0)
    {
    MessageBox(NULL,"讀取文件失敗","error",MB_OK);
    }
    return;
    }