分类: WINDOWS
2012-06-15 14:54:59
STDMETHODIMP CReadFile:: LoadFile (BSTR FileName,BOOL* result) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) CStdioFile f; CString FileData; Cstring Datas[255]; //用于存放从文件中读出的数据 int i=0; //数组下标 USES_CONVERSION; if(f.Open(W2A(FileName),CFile::modeRead)) { //文件成功打开 while(f.ReadString(FileData)) { //处理读出的数据 Datas[i]= FileData; i++; } f.Close(); *result=true; return S_OK; //关闭文件,返回结果为真 } else { //文件打开失败 *result=false; //返回参数为false return E_FAIL; } } |
#include #include "..\DataAccess_i.c" #include "..\DataAccess.h" |
IReadFile * pIRF=NULL; BOOL result=false; //初始化com库 HRESULT hr=::CoInitialize(NULL); if(FAILED(hr)) { //初始化失败 return -1; } hr=::CoCreateInstance(CLSID_ReadFile,NULL,CLSCTX_INPROC_SERVER,IID_IReadFile, (void**)&pIRF); if(FAILED(hr)) { //创建组件实例失败 return -1; } USES_CONVERSION; CString FILENAME=".\\Palette.txt"; hr=pIRF->LoadFile(A2W(FILENAME),&result); if(FAILED(hr)) { return -1; } |