本文整理汇总了C++中AfxThrowFileException函数的典型用法代码示例。如果您正苦于以下问题:C++ AfxThrowFileException函数的具体用法?C++ AfxThrowFileException怎么用?C++ AfxThrowFileException使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AfxThrowFileException函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT_VALID
UINT CStdioFile::Read(void* lpBuf, UINT nCount)
{
ASSERT_VALID(this);
ASSERT(m_pStream != NULL);
if (nCount == 0)
return 0; // avoid Win32 "null-read"
ASSERT(AfxIsValidAddress(lpBuf, nCount));
if (lpBuf == NULL)
{
AfxThrowInvalidArgException();
}
UINT nRead = 0;
if ((nRead = (UINT)fread(lpBuf, sizeof(BYTE), nCount, m_pStream)) == 0 && !feof(m_pStream))
AfxThrowFileException(CFileException::genericException, _doserrno, m_strFileName);
if (ferror(m_pStream))
{
Afx_clearerr_s(m_pStream);
AfxThrowFileException(CFileException::genericException, _doserrno, m_strFileName);
}
return nRead;
}
示例2: AfxThrowFileException
UINT CBuffFile::Read(void* lpBuf, UINT nCount)
{
UINT nRead = 0;
if ((nRead = fread(lpBuf, sizeof(BYTE), nCount, m_pStream)) == 0 && !feof(m_pStream))
AfxThrowFileException(CFileException::generic, _doserrno);
if (ferror(m_pStream))
{
clearerr(m_pStream);
AfxThrowFileException(CFileException::generic, _doserrno);
}
return nRead;
}
示例3: switch
LONG CMyMemFile::Seek(LONG lOff, UINT nFrom)
{
switch(nFrom)
{
case CFile::begin:
if(NULL != m_pData)
{
m_pData -= m_dwLength;
m_pData += lOff;
}
m_dwLength = lOff;
break;
case CFile::current:
if(NULL != m_pData)
{
m_pData += lOff;
}
m_dwLength += lOff;
break;
case CFile::end:
default:
AfxThrowFileException(CFileException::badSeek);
}
return m_dwLength;
}
示例4: AfxThrowFileException
void PASCAL CFileException::ThrowErrno(int nErrno,
LPCTSTR lpszFileName /* = NULL */)
{
if (nErrno != 0)
AfxThrowFileException(CFileException::ErrnoToException(nErrno),
_doserrno, lpszFileName);
}
示例5: ASSERT
void CStdioFileEx::WriteWideString(LPCWSTR lpsz)
{
ASSERT(lpsz != NULL);
if (lpsz == NULL)
{
AfxThrowInvalidArgException();
}
if(m_bIsUnicodeText)
{
ASSERT(m_pStream != NULL);
// If writing Unicode and at the start of the file, need to write byte mark
if(GetPosition() == 0)
{
wchar_t cBOM = (wchar_t)UNICODE_BOM;
CFile::Write(&cBOM, sizeof(wchar_t));
}
if (fputws(lpsz, m_pStream) == _TEOF)
AfxThrowFileException(CFileException::diskFull, _doserrno, m_strFileName);
}
else
{
USES_CONVERSION;
WriteAnsiString(CW2A(lpsz));
}
}
示例6: ASSERT
UINT CConverter::Read(void FAR* lpBuf, UINT nCount)
{
ASSERT(m_bForeignToRtf);
if (m_bDone)
return 0;
// if converter is done
int cch = nCount;
BYTE* pBuf = (BYTE*)lpBuf;
while (cch != 0)
{
if (m_nBytesAvail == 0)
{
if (m_pBuf != NULL)
GlobalUnlock(m_hBuff);
m_pBuf = NULL;
SetEvent(m_hEventConv);
WaitForConverter();
VERIFY(ResetEvent(m_hEventFile));
if (m_bConvErr)
AfxThrowFileException(CFileException::generic);
if (m_bDone)
return nCount - cch;
m_pBuf = (BYTE*)GlobalLock(m_hBuff);
ASSERT(m_pBuf != NULL);
}
int nBytes = min(cch, m_nBytesAvail);
memcpy(pBuf, m_pBuf, nBytes);
pBuf += nBytes;
m_pBuf += nBytes;
m_nBytesAvail -= nBytes;
cch -= nBytes;
OutputPercent(m_nPercent);
}
return nCount - cch;
}
示例7: CMemFile
COXRegistryValFile::COXRegistryValFile(HKEY hkey, LPCTSTR lpszKey, LPCTSTR lpszValue)
: CMemFile(1024), m_key(0)
{
LONG error;
if (!Open(hkey, lpszKey, lpszValue, error))
AfxThrowFileException(CFileException::accessDenied, error, lpszKey);
}
示例8: AfxThrowFileException
uint64 CSafeMemFile::ReadUInt64()
{
if (m_nPosition + sizeof(uint64) > m_nFileSize)
AfxThrowFileException(CFileException::endOfFile, 0, GetFileName());
uint64 nResult = *((uint64*)(m_lpBuffer + m_nPosition));
m_nPosition += sizeof(uint64);
return nResult;
}
示例9: ASSERT
void CStdioFile::WriteString(LPCTSTR lpsz)
{
ASSERT(lpsz != NULL);
ASSERT(m_pStream != NULL);
if (_fputts(lpsz, m_pStream) == _TEOF)
AfxThrowFileException(CFileException::diskFull, _doserrno, m_strFileName);
}
示例10: ASSERT_VALID
void CStdioFile::Flush()
{
ASSERT_VALID(this);
if (m_pStream != NULL && fflush(m_pStream) != 0)
AfxThrowFileException(CFileException::diskFull, _doserrno,
m_strFileName);
}
示例11: va_start
int CSafeBufferedFile::printf(LPCTSTR pszFmt, ...)
{
va_list args;
va_start(args, pszFmt);
int iResult = _vftprintf(m_pStream, pszFmt, args);
va_end(args);
if (iResult < 0)
AfxThrowFileException(CFileException::generic, _doserrno, m_strFileName);
return iResult;
}
示例12: AfxThrowFileException
void PASCAL CFileException::ThrowErrno(int nErrno)
{
if (nErrno != 0)
AfxThrowFileException(CFileException::ErrnoToException(nErrno),
#ifndef _MAC
_doserrno);
#else
GetLastError());
#endif
}
示例13: ASSERT
void CSocketFile::Write(const void* lpBuf, UINT nCount)
{
ASSERT (m_pSocket!=NULL);
int nWritten = m_pSocket->Send(lpBuf, nCount);
if (nWritten == SOCKET_ERROR)
{
int nError = m_pSocket->GetLastError();
AfxThrowFileException(CFileException::generic, nError);
}
}
示例14: _ASSERTE
BOOL CStdioFileEx::ReadWideString(CStringW& rString)
{
_ASSERTE(m_pStream);
rString = L"";// empty string without deallocating
if(m_bIsUnicodeText)
{
// If at position 0, discard byte-order mark before reading
if(GetPosition() == 0)
{
wchar_t bom;
Read(&bom, sizeof(wchar_t));
}
const int nMaxSize = 128;
LPWSTR lpsz = rString.GetBuffer(nMaxSize);
LPWSTR lpszResult;
int nLen = 0;
for (;;)
{
lpszResult = fgetws(lpsz, nMaxSize+1, m_pStream);
rString.ReleaseBuffer();
// handle error/eof case
if (lpszResult == NULL && !feof(m_pStream))
{
Afx_clearerr_s(m_pStream);
AfxThrowFileException(CFileException::genericException, _doserrno,
m_strFileName);
}
// if string is read completely or EOF
if (lpszResult == NULL || (nLen = (int)lstrlenW(lpsz)) < nMaxSize || lpsz[nLen-1] == '\n')
break;
nLen = rString.GetLength();
lpsz = rString.GetBuffer(nMaxSize + nLen) + nLen;
}
//remove crlf if exist.
nLen = rString.GetLength();
if (nLen > 1 && rString.Mid(nLen-2) == L"\r\n")
{
rString.GetBufferSetLength(nLen-2);
}
return rString.GetLength() > 0;
}
else
{
CStringA ansiString;
BOOL bRetval = ReadAnsiString(ansiString);
//setlocale(LC_ALL, "chs_chn.936");//no need
rString = ansiString;
return bRetval;
}
}
示例15: fclose
void CBuffFile::Close()
{
int nErr= 0;
if (m_pStream != NULL)
nErr = fclose(m_pStream);
m_hFile = hFileNull;
m_bCloseOnDelete = FALSE;
m_pStream = NULL;
if (nErr != 0)
AfxThrowFileException(CFileException::diskFull, _doserrno);
}