本文整理汇总了C++中CFile::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ CFile::GetLength方法的具体用法?C++ CFile::GetLength怎么用?C++ CFile::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFile
的用法示例。
在下文中一共展示了CFile::GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddFile
BOOL EM_FILEINFO::AddFile(LPCTSTR lpszFileFullName, LPCTSTR lpszFileExt)
{
ASSERT(lpszFileFullName != NULL);
CFile file;
BOOL bResult = file.Open(lpszFileFullName, CFile::modeRead|CFile::shareDenyNone, NULL);
if(!bResult)
{
EM_Error("EM_FILEINFO::AddFile could not open file.", GetLastError());
return FALSE;
}
dwSize = file.GetLength();
strcpy(szName, (LPCTSTR)file.GetFileName());
strcpy(szFullName, lpszFileFullName);
strcpy(szExt, lpszFileExt);
// 关闭文件
file.Close();
return bResult;
}
示例2: UploadImg
// 上传img图片logo
int Enconn::UploadImg(CString filePath, LogoInfo position,int type)
{
int length;
CFile file;
char pData[1024] = {0};
if(file.Open(filePath,CFile::typeBinary|CFile::modeRead)==FALSE)
{
::AfxMessageBox(_T("打开文件失败"));
return -1;
}
length=file.GetLength();
printf("img file length=%d\n",length);
if(length<1)return -1;
if(Enctype==1)//ENC1200
{
PackHeaderMSG((BYTE *)pData, MSG_SET_LOGOINFO, (HEAD_LEN+1+sizeof(LogoInfo)));
pData[HEAD_LEN]=type;
memcpy(pData+HEAD_LEN+1,&position,sizeof(LogoInfo));
*(int*)((pData+HEAD_LEN+1+sizeof(LogoInfo)))=(length);
Send(pData,HEAD_LEN+1+sizeof(LogoInfo)+4);
}
else
{
*(short*)(&pData)=htons(4+sizeof(LogoInfo));
pData[2]=MSG_SET_LOGOINFO;
pData[3]=type;
memcpy(pData+4,&position,sizeof(LogoInfo));
*(int*)((pData+4+sizeof(LogoInfo)))=(length);
Send(pData,8+sizeof(LogoInfo));
}
while(length)
{
length=file.Read(pData,512);
Send(pData,length);
}
return 0;
}
示例3: LoadFromFile
BOOL CBCGPBaseInfoLoader::LoadFromFile (LPCTSTR lpszFileName)
{
if (lpszFileName == NULL)
{
ASSERT(FALSE);
return FALSE;
}
CFileException e;
CFile file;
if (!file.Open (lpszFileName, CFile::modeRead | CFile::typeBinary, &e))
{
ASSERT(FALSE);
return FALSE;
}
int nLength = (int)file.GetLength ();
LPBYTE lpszBuffer = new BYTE[nLength];
file.Read (lpszBuffer, nLength);
LPTSTR lpszXML = NULL;
CBCGPTagManager::UTF8ToString ((LPCSTR)lpszBuffer, lpszXML, nLength);
delete [] lpszBuffer;
file.Close();
BOOL bRes = FALSE;
if (lpszXML != NULL)
{
bRes = LoadFromBuffer (lpszXML);
delete [] lpszXML;
}
return bRes;
}
示例4: OpenUpdateInfo
BOOL CUpdateInfo::OpenUpdateInfo(void)
{
CFile file;
if (file.Open(GetUpdateInfoFile(), CFile::modeRead))
{
int nLen = file.GetLength();
try
{
CArchive ar(&file, CArchive::load);
/*
*兼容老版本的update.dat文件
*added by zhuhui 2010-5-13
*begin
*/
switch(nLen)
{
case 68:
Serialize(ar);
break;
default:
Serialize1(ar);
}
//end 兼容老版本的update.dat文件
}
catch (CException* e)
{
e->Delete();
ASSERT(0);
}
file.Close();
return TRUE;
}
return FALSE;
}
示例5: BloadFile
// Bloads a file into memory.
unsigned char* BloadFile(CString sFilename, int& nNumBytes)
{
CFile hFile;
nNumBytes = 0;
if(!hFile.Open(sFilename, CFile::modeRead | CFile::shareDenyWrite | CFile::typeBinary))
return NULL;
nNumBytes = hFile.GetLength();
if(nNumBytes == 0)
{
hFile.Close();
return NULL;
}
// Allocate.
unsigned char* pData = new unsigned char[nNumBytes];
if(pData == NULL)
{
hFile.Close();
nNumBytes = 0;
return NULL;
}
// Load the file.
if(hFile.Read(pData, nNumBytes) != (unsigned int)nNumBytes)
{
hFile.Close();
nNumBytes = 0;
delete[] pData;
return NULL;
}
hFile.Close();
return pData;
}
示例6: Load
BOOL CWave::Load( const char *lpszFilename )
{
Close();
CFile File;
if( !File.Open( lpszFilename, CFile::modeRead ) )
return( FALSE );
DWORD dwFileLength = File.GetLength();
m_lpSoundData = new char [dwFileLength];
if( m_lpSoundData == NULL )
return( FALSE );
if( File.Read( m_lpSoundData, dwFileLength )
!= dwFileLength )
return( FALSE );
m_bLoaded = TRUE;
return( TRUE );
}
示例7:
void CRegsterDialog::ReceiveIP2()
{
//接收服务器IP地址
CHttpDownLoadDlg udlg;
udlg.m_URL = SERVERLISTURL;
udlg.m_Path.Format("%s\\temp\\update.web", CurrentPath);
//IP地址(带端口)#默认状态#服务器描述
if(udlg.DoModal() == IDOK){
CFile cf;
if(cf.Open(udlg.m_Path, CFile::modeRead)){
long flen = cf.GetLength();
char* buf = (char*)malloc(flen+1);
ZeroMemory(buf, flen+1);
cf.Read(buf, flen);
cf.Close();
SaveServersInfo(buf);
free(buf);
}
}
else
MessageBox("获取服务器地址失败", "错误", MB_OK|MB_ICONWARNING);
DeleteFile(udlg.m_Path);
}
示例8: SerializeRaw
void CEditView::SerializeRaw(CArchive& ar)
// Read/Write object as stand-alone file.
{
ASSERT_VALID(this);
if (ar.IsStoring())
{
WriteToArchive(ar);
}
else
{
CFile* pFile = ar.GetFile();
ASSERT(pFile->GetPosition() == 0);
DWORD nFileSize = pFile->GetLength();
if (nFileSize/sizeof(TCHAR) > nMaxSize)
{
AfxMessageBox(AFX_IDP_FILE_TOO_LARGE);
AfxThrowUserException();
}
// ReadFromArchive takes the number of characters as argument
ReadFromArchive(ar, (UINT)nFileSize/sizeof(TCHAR));
}
ASSERT_VALID(this);
}
示例9: ReadInHostCache
void ConnectionManager::ReadInHostCache()
{
UINT i;
// If there is a hosts.dat file, read it into the hosts cache
CFile file;
if(file.Open("C:\\syncher\\src\\GnutellaHostCache\\hosts.dat",CFile::modeRead|CFile::typeBinary|CFile::shareDenyNone)==TRUE)
{
// Create a buffer in memory to read in the hosts cache file
unsigned int buf_len=(UINT)file.GetLength();
char *buf=new char[buf_len];
file.Read(buf,buf_len); // read in the file
file.Close();
char *ptr=buf;
// Read in the number of hosts in the hosts.dat file
unsigned int num_hosts=*((unsigned int *)ptr);
ptr+=sizeof(unsigned int);
// Copy the hosts from the buffer
for(i=0;i<num_hosts;i++)
{
GnutellaHost host;
host.IP(*((unsigned int *)ptr));
ptr+=sizeof(unsigned int);
host.Port(*((unsigned int *)ptr));
ptr+=sizeof(unsigned int);
if(FilterHost(host.Host().c_str())==false)
v_host_cache.push_back(host);
}
delete [] buf;
}
}
示例10: ReadShortMsgFromFile
BOOL CPorpJudgeShortMsg::ReadShortMsgFromFile()
{
ReleaseShortMsg();
CFile file;
CFileException e;
if (file.Open(m_filePath,CFile::modeRead,&e))
{
////注意序列化出来的指针变量已经分配了内存
CJudgeShortMsg* pJudgeShortMsg = NULL;
UINT cardConfigID = 0;
CArchive ar(&file,CArchive::load);
if (file.GetLength())
{
do
{
ar>>pJudgeShortMsg;
if (pJudgeShortMsg)
{
//界面显示
CString strSerialID;
strSerialID.Format(_T("%d"),pJudgeShortMsg->GetJudgeShortMsgSerialID());
int count = m_listctr_content.GetItemCount();
int nItem = 1;
m_listctr_content.InsertItem(count,strSerialID);
m_listctr_content.SetItemText(count,nItem++,pJudgeShortMsg->GetPhoneNum());
m_listctr_content.SetItemText(count,nItem++,pJudgeShortMsg->GetShortMsg());
m_list_judgeMsg.push_back(pJudgeShortMsg);
cardConfigID = pJudgeShortMsg->GetJudgeShortMsgSerialID() > cardConfigID
? pJudgeShortMsg->GetJudgeShortMsgSerialID() : cardConfigID;
}
}while(!ar.IsBufferEmpty());
}
ar.Close();
file.Close();
g_JudgeShortMsgSerialID = cardConfigID;
}
示例11: ParseEntity
void MeaPositionLogMgr::ParseEntity(MeaXMLParser& parser,
const CString& pathname)
{
CFile entityFile;
CFileException fe;
if (!entityFile.Open(pathname, CFile::modeRead, &fe)) {
AfxThrowFileException(fe.m_cause, fe.m_lOsError, pathname);
}
MeaXMLParser entityParser(parser);
// Read the contents of the entity file into a parsing buffer.
//
int size = static_cast<int>(entityFile.GetLength());
void *buf = entityParser.GetBuffer(size);
UINT count = entityFile.Read(buf, size);
// Parse the entity file
//
entityParser.ParseBuffer(count, true);
entityFile.Close();
}
示例12: ReadCtrInfoFromFile
BOOL CHallQueFrontView::ReadCtrInfoFromFile()
{
CCommonConvert convert;
CString exepath = convert.GetExeFullFilePath();
exepath += _T("\\wndctrinfo.dat");
CFile file;
if(file.Open(exepath,CFile::modeRead))
{
ULONGLONG count=file.GetLength()/sizeof(WINDOWCTRINFO);
for(ULONGLONG i=0;i<count;i++)
{
WINDOWCTRINFO windowctrinfo;
if(file.Read(&windowctrinfo,sizeof(WINDOWCTRINFO))>0)
{
m_list_allCtrInfo.AddTail(windowctrinfo);
}
}
return TRUE;
}
else
{
return FALSE;
}
}
示例13: ReadStaffInfoFromFile
BOOL SLZWindowSetDlg::ReadStaffInfoFromFile()
{
CFile file;
CFileException e;
if (file.Open(m_staffinfo_path,CFile::modeRead,&e))
{
SLZStaff* staffinfo=NULL;
CArchive ar(&file,CArchive::load);
if (file.GetLength())
do
{
ar>>staffinfo;
if (staffinfo)
{
m_map_staff[m_cs_LogStaff.AddString(staffinfo->GetStaffName())-1]
= *staffinfo;
delete staffinfo;
staffinfo = NULL;
}
}while(!ar.IsBufferEmpty());
ar.Close();
file.Close();
return TRUE;
}
示例14: OnOpen
//打开按钮
void CChessManual::OnOpen()
{
//获取目录
TCHAR szPath[MAX_PATH]=TEXT("");
GetCurrentDirectory(sizeof(szPath),szPath);
//选择文件
LPCTSTR pszFilter=TEXT("中国象棋棋谱文件 (*.CCM)|*.CCM||");
CFileDialog DlgOpenManual(TRUE,TEXT("CHM"),NULL,OFN_NOCHANGEDIR|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,pszFilter);
DlgOpenManual.m_pOFN->lpstrInitialDir=szPath;
if (DlgOpenManual.DoModal()!=IDOK) return;
//打开文件
CFile FileManual;
if (FileManual.Open(DlgOpenManual.GetPathName(),CFile::modeRead)==FALSE)
{
AfxMessageBox(TEXT("无法打开文件,棋谱打开失败!"),MB_ICONSTOP);
return;
}
//判断文件
DWORD dwFileLength=(DWORD)FileManual.GetLength();
if (dwFileLength<sizeof(tagChessManualHead))
{
AfxMessageBox(TEXT("棋谱文件格式错误,棋谱打开失败!"),MB_ICONSTOP);
return;
}
//文件头
tagChessManualHead ChessManualHead;
FileManual.Read(&ChessManualHead,sizeof(ChessManualHead));
//效验版本
if (ChessManualHead.wVersion!=VER_MANUAL)
{
AfxMessageBox(TEXT("棋谱文件版本错误,棋谱打开失败!"),MB_ICONSTOP);
return;
}
//效验长度
if ((ChessManualHead.dwManualCount*sizeof(tagChessManual)+sizeof(tagChessManualHead))!=dwFileLength)
{
AfxMessageBox(TEXT("棋谱文件长度错误,棋谱打开失败!"),MB_ICONSTOP);
return;
}
//读取棋谱
tagChessManual * pChessManual=NULL;
m_ChessManualInfo.SetSize(ChessManualHead.dwManualCount);
for (DWORD i=0;i<ChessManualHead.dwManualCount;i++)
{
pChessManual=&m_ChessManualInfo[i];
FileManual.Read(pChessManual,sizeof(tagChessManual));
}
//关闭文件
FileManual.Close();
//设置界面
m_wChessStep=0;
m_GameLogic.ResetChessBorad();
m_ChessBorad.SetChessFrame(255,255,255,255);
m_ChessBorad.SetChessBorad(m_GameLogic.m_ChessBorad);
m_ChessBorad.SetChessColor(ChessManualHead.cbChessColor);
//更新列表
UpdateManualList();
//更新控制
UpdateControl();
return;
}
示例15: decoder_load
//.........这里部分代码省略.........
if (pCachedBank) delete pCachedBank;
pCachedBank = new CDLSBank;
strcpy(szCachedBankFile, pszMidiMapName);
if (pCachedBank->Open(pszMidiMapName)) pDLSBank = pCachedBank;
}
if (pDLSBank)
{
UINT nDlsIns = 0, nDrumRgn = 0;
UINT nProgram = penv->nMidiProgram;
UINT dwKey = (nMidiCode < 128) ? 0xFF : (nMidiCode & 0x7F);
if ((pDLSBank->FindInstrument( (nMidiCode >= 128),
(penv->wMidiBank & 0x3FFF),
nProgram, dwKey, &nDlsIns))
|| (pDLSBank->FindInstrument( (nMidiCode >= 128), 0xFFFF,
(nMidiCode >= 128) ? 0xFF : nProgram,
dwKey, &nDlsIns)))
{
if (dwKey < 0x80) nDrumRgn = pDLSBank->GetRegionFromKey(nDlsIns, dwKey);
pDLSBank->ExtractInstrument(&pstreams[id].csnd, nIns, nDlsIns, nDrumRgn);
if ((dwKey >= 24) && (dwKey < 24+61))
{
lstrcpyn(penv->name, szMidiPercussionNames[dwKey-24], sizeof(penv->name));
}
}
}
} else
{
// Load from Instrument or Sample file
CHAR szName[_MAX_FNAME], szExt[_MAX_EXT];
CFile f;
if (f.Open(pszMidiMapName, CFile::modeRead))
{
DWORD len = f.GetLength();
LPBYTE lpFile;
if ((len) && ((lpFile = (LPBYTE)GlobalAllocPtr(GHND, len)) != NULL))
{
f.Read(lpFile, len);
pstreams[id].csnd.ReadInstrumentFromFile(nIns, lpFile, len);
_splitpath(pszMidiMapName, NULL, NULL, szName, szExt);
strncat(szName, szExt, sizeof(szName));
penv = pstreams[id].csnd.Headers[nIns];
if (!penv->filename[0]) lstrcpyn(penv->filename, szName, sizeof(penv->filename));
if (!penv->name[0])
{
if (nMidiCode < 128)
{
lstrcpyn(penv->name, szMidiProgramNames[nMidiCode], sizeof(penv->name));
} else
{
UINT nKey = nMidiCode & 0x7F;
if (nKey >= 24)
lstrcpyn(penv->name, szMidiPercussionNames[nKey-24], sizeof(penv->name));
}
}
}
f.Close();
}
}
}
}
if (pCachedBank) delete pCachedBank;
if (pEmbeddedBank) delete pEmbeddedBank;
//EndWaitCursor();
}
// Convert to MOD/S3M/XM/IT