readfile:C++ Win32API ReadFile()读取文件

直接一起来看吧:

#include <iostream.h>
#include <Windows.h>
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>


void main()
{

unsigned long lpNumber=0;
char lpBuffer[50]="";//文件读取的内容
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,"创建文件句柄出错","error",MB_OK);
}

int filesucc=ReadFile(hFile,
lpBuffer,
50,//读取文件中多少内容
&lpNumber,
NULL
);
CloseHandle(hFile);
if(filesucc==0)
{
MessageBox(NULL,"读取文件失败","error",MB_OK);
}
return;
}

Tags:  新编win32api大全 vcreadfile win32api readfile

延伸阅读

最新评论

发表评论