当前位置: 首页>>代码示例>>C++>>正文


C++ CAtlFile::Write方法代码示例

本文整理汇总了C++中CAtlFile::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ CAtlFile::Write方法的具体用法?C++ CAtlFile::Write怎么用?C++ CAtlFile::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CAtlFile的用法示例。


在下文中一共展示了CAtlFile::Write方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SetContiInfo

bool CDTManager::SetContiInfo( CString file,CString& url,int64& len,int& cur )
{
	CAtlFile f;
	if(ERROR_SUCCESS!=f.Create(file,FILE_GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,CREATE_ALWAYS)!=ERROR_SUCCESS)
	{
		return false;
	}
	f.Write(&len,sizeof len);
	f.Write(&cur,sizeof cur);
	f.Write(url.GetBuffer(),url.GetLength()*2+2);
	f.Close();
	return true;
}
开发者ID:dreamsxin,项目名称:PcManager,代码行数:13,代码来源:DTManager.cpp

示例2: SaveWords

bool Speller::SaveWords( LPCTSTR path, const WordContainer& words )
{
	CAtlFile file;
	bool result = false;

	if (SUCCEEDED(file.Create(path, GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS)))
	{
		WordContainer::const_iterator it = words.begin();
		std::vector<char> data;

		for (; it != words.end(); ++it) 
		{
			data.clear();
			const StringType text = *it + _T("\n");

			UTF16toUTF8(text.c_str(), text.size(), data);

			if (!data.empty())
				file.Write(&data[0], static_cast<DWORD>(data.size()));
		}

		result = true;
	}

	return result;
}
开发者ID:bzindovic,项目名称:texniccenter-code,代码行数:26,代码来源:Speller.cpp

示例3: StreamFileOut

DWORD CALLBACK LogViewRE::StreamFileOut(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
  CAtlFile* file = (CAtlFile*)dwCookie;
  if (!file)
    return ERROR_INVALID_FUNCTION;
  return file->Write(pbBuff, cb, (DWORD*)pcb);
}
开发者ID:IUnknown68,项目名称:PumpkinLog,代码行数:7,代码来源:LogViewRE.cpp

示例4: file_put_contents

BOOL file_put_contents(LPCTSTR lpszFilename, BYTE *pBuffer, INT nLen)
{
	CAtlFile file;
	if( FAILED( file.Create(lpszFilename, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, CREATE_ALWAYS) ) )
		return FALSE;
	
	file.Write( pBuffer, nLen );
	file.Close();
	return TRUE;
}
开发者ID:6520874,项目名称:pcmanager,代码行数:10,代码来源:BeikeUtils.cpp

示例5: OnSave

/**
 * @param uNotifyCode - notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero.
 * @param nID - specifies the identifier of the menu item, control, or accelerator.
 * @param hWndCtl - handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL.
 */
void CExpressModeDlg::OnSave(UINT /*uNotifyCode*/, int /*nID*/, HWND /*hWndCtl*/)
{
	try
	{
		if (! ValidateXMLDocument())
			return;
		CString strLogFile;
		GetReportFileName(strLogFile);
		CCustomFileDialog dlgSaveFile(FALSE,
			_T("xml"),
			strLogFile,
			OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST,
			_T("Log Files\0*.log\0All Files\0*.*\0"),
			m_hWnd);
		if (dlgSaveFile.DoModal(m_hWnd) == IDOK)
		{
			CAtlFile fileLog;
			if (fileLog.Create(dlgSaveFile.m_szFileName, GENERIC_WRITE, 0, CREATE_ALWAYS) == S_OK)
			{
				CString strLogText;
				GetErrorLog(strLogText);
				CT2CW pchUnicodeText(strLogText);
				int nDestSize = AtlUnicodeToUTF8(pchUnicodeText, strLogText.GetLength(), NULL, 0);
				if (nDestSize >= 0)
				{
					static const BYTE arrUTF8Preamble[] = { 0xEF, 0xBB, 0xBF };
					int nTotalDestSize = sizeof(arrUTF8Preamble) + nDestSize;
					boost::scoped_array<CHAR> pchDest(new CHAR[nTotalDestSize]);
					CopyMemory(pchDest.get(), arrUTF8Preamble, sizeof(arrUTF8Preamble));
					AtlUnicodeToUTF8(pchUnicodeText, strLogText.GetLength(), pchDest.get() + sizeof(arrUTF8Preamble), nDestSize);
					fileLog.Write(pchDest.get(), nTotalDestSize);
				}
			}
		}
	}
	catch (std::exception& error)
	{
		HandleException(error);
	}
}
开发者ID:Charsi82,项目名称:x-ray1.5.10-2016-,代码行数:45,代码来源:ExpressModeDlg.cpp

示例6: _output_file

	virtual void _output_file(CAtlString& string) { _file.Write(static_cast<const TCHAR*>(string), string.GetLength()); }
开发者ID:kaina,项目名称:sandbox,代码行数:1,代码来源:debugout.hpp

示例7: UrlUnescapeInPlace


//.........这里部分代码省略.........
	if (pData->m_pUrlInfo->m_dwDownloadFlags & HTTP_FLAG_NO_RESUME)
		DeleteFile(pData->m_pUrlInfo->m_DownloadFile); 

    hr = OutFile.Create(pData->m_pUrlInfo->m_DownloadFile, GENERIC_WRITE, 0, OPEN_ALWAYS);

    if (FAILED(hr))
    {
		_DBGAlert("**FAsyncDownload::FHttpDownloadTP::ProcessDownload: CreateFile failed: 0x%x, %d : %s\n", hr, GetLastError(), pData->m_pUrlInfo->m_DownloadFile); 
        return E_HTTP_WRITE_FILE; 
    }

    size_type llTotalRead = 0; 
    size_type llSizeMax = 0; 

	size_type ContentLen = FConn.GetContentLength(); 

	pData->m_pUrlInfo->m_ContentLength = ContentLen; 

    if (dwStatusCode == 206)
    {
        FString FStrRange = FConn.GetHeader(HTTP_QUERY_CONTENT_RANGE);
        
        if (FStrRange)
        {
           //Content-Range: bytes 21010-47021/47022
           const char* pszBytes = strstr(FStrRange, "bytes ");
           if (pszBytes != NULL)
           {
               pszBytes+=sizeof("bytes");
               LONGLONG llOffset = _strtoi64(pszBytes, NULL, 10); 
               hr = OutFile.Seek(llOffset, FILE_BEGIN); 
               llTotalRead = (size_type)llOffset; 
               if (FAILED(hr))
               {
                   _DBGAlert("**FAsyncDownload::FHttpDownloadTP::ProcessDownload: Seek to position %d failed: 0x%x, %d\n", hr, GetLastError()); 
               }

               const char* pszTotal = strchr(pszBytes, '/');
               if (pszTotal != NULL)
                   llSizeMax = _strtoi64(pszTotal + 1, NULL, 10); 
           }
        }
    }
	else
	{
		if (ContentLen > 0 && ContentLen == FileSize)
		{
			OutFile.Close();
			return S_OK; 
		}
	}

    if (llSizeMax == 0)
		llSizeMax = ContentLen;


    pData->pBindStatusCallback.OnProgress((ULONG)llTotalRead, (ULONG)llSizeMax, BINDSTATUS_BEGINDOWNLOADDATA, L"");

    DWORD dwBytesRead = 0; 
    for (;;)
    {
        if (!InternetReadFile(hReq, pBuffer, dwBufferSize, &dwBytesRead))
        {
            _DBGAlert("**FAsyncDownload::FHttpDownloadTP::ProcessDownload: InternetReadFile() failed: %d\n", GetLastError()); 
			OutFile.Close();
            return E_HTTP_NET_ERROR; 
        }

		if (dwBytesRead == 0)
		{
			hr = S_OK; 
			break; 
		}

        DWORD dwBytesWritten = 0; 
        hr = OutFile.Write(pBuffer, dwBytesRead, &dwBytesWritten); 

		if (FAILED(hr))
        {
            _DBGAlert("**FAsyncDownload::FHttpDownloadTP::ProcessDownload: FileWrite failed: 0x%x, %d\n", hr, GetLastError()); 
			OutFile.Close();
            return E_HTTP_WRITE_FILE; 
        }

        llTotalRead+=dwBytesRead;
		
		pData->pBindStatusCallback.OnProgress((ULONG)llTotalRead, llSizeMax > 0 ? (ULONG)llSizeMax : llTotalRead , BINDSTATUS_DOWNLOADINGDATA, L"");


        if (m_pThis->m_Stopping || pData->pBindStatusCallback.m_Abort)
        {
            _DBGAlert("**FAsyncDownload::FHttpDownloadTP::ProcessDownload: Download aborted\n", hr, GetLastError()); 
            hr = E_ABORT; 
            break; 
        }
    }

	OutFile.Close();
    return hr; 
}
开发者ID:codeboost,项目名称:libertv,代码行数:101,代码来源:FAsyncHttpDownload.cpp

示例8: Fetch

BOOL CLocalFileDownload::Fetch( INT nCorrurent/*=0*/ )
{
	m_bStopped = FALSE;
	
	try
	{
		CFileInStream fin(m_strUrl);
		if(!fin.Create())
		{
			m_errCode = DLLER_SERVER_FILENOTFOUND;
			return FALSE;
		}

		CString strTmpFile;
		strTmpFile.Format(_T("%s%s"), m_strFilePath, _T(".tc"));
		CAtlFile file;	
		if( FAILED( file.Create(strTmpFile, GENERIC_WRITE, FILE_SHARE_WRITE, CREATE_ALWAYS) ) )
		{
			m_errCode = DLERR_CREATEFILE;
			return FALSE;
		}
		
		m_errCode = DLERR_SUCCESS;
		m_FileInfo.Reset(fin.GetFileSize(), 0, TRUE);
		m_DownStat.OnDownBegin();
		
		int64 lastDownloaded = 0, downloadedPercent = m_FileInfo.fileSize/100;

		const int nBufferSize = 1024;
		BYTE *pBuffer = new BYTE[nBufferSize];
		while(!m_bStopped)
		{
			DWORD dwReaded = 0;
			fin.Read(pBuffer, nBufferSize, &dwReaded);
			if(dwReaded==0)
				break;
			
			DWORD dwWrited = 0;
			if( FAILED(file.Write(pBuffer, dwReaded, &dwWrited)) || dwWrited!=dwReaded)
			{
				m_errCode = DLERR_WRITEFILE;
				break;
			}

			m_FileInfo.fileDownloaded += dwReaded;			
			if((m_FileInfo.fileDownloaded-lastDownloaded) > downloadedPercent)
			{
				m_DownStat.OnDownData(GetTickCount(), (m_FileInfo.fileDownloaded-lastDownloaded));
				lastDownloaded = m_FileInfo.fileDownloaded;
				_Notify(ProcessState_ReceiveData);
			}
		}
		fin.CloseFile();
		file.Close();
		SAFE_DELETE_ARRAY(pBuffer);
		m_DownStat.OnDownEnd();
		
		if(m_FileInfo.fileDownloaded==m_FileInfo.fileSize)
		{
			MoveFileEx(strTmpFile, m_strFilePath, MOVEFILE_REPLACE_EXISTING);
			m_errCode = DLERR_SUCCESS;
		}
		else
		{
			DeleteFile(strTmpFile);
			m_errCode = DLLER_NETWORK;
		}
	}
	catch (...)
	{
		m_errCode = DLERR_WRITEFILE;
	}
	return DLERR_SUCCESS==m_errCode;
}
开发者ID:dreamsxin,项目名称:PcManager,代码行数:74,代码来源:LocalFileDownload.cpp

示例9: EncodeFile

HRESULT CZlib::EncodeFile( LPCWSTR lpwszSrcFile, LPCWSTR lpwszDstFile, int level )
{
    if ( zlib_compress )
    {
        CAtlFile hInFile;
        HRESULT hr = hInFile.Create(
            lpwszSrcFile,
            GENERIC_READ,
            FILE_SHARE_READ | FILE_SHARE_DELETE,
            OPEN_EXISTING);
        if (FAILED(hr))
            return hr;

        CAtlFile hOutFile;
        hr = hOutFile.Create(
            lpwszDstFile,
            GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_DELETE,
            CREATE_ALWAYS);
        if (FAILED(hr))
            return hr;

        ULONGLONG uInFileSize = 0;
        hr = hInFile.GetSize(uInFileSize);
        if (FAILED(hr))
            return hr;

        // 0长度文件不需要压缩
        if (0 == uInFileSize)
            return S_OK;

        // 太大的文件不压缩
        if (uInFileSize >  ZLIB_SINGLE_FILE_MAX_SIZE ) //假定压缩比为4:1
            return E_FAIL;

        // 读取输入
        CAtlArray<BYTE> bufRead;
        bufRead.SetCount((size_t)uInFileSize);
        if (uInFileSize != bufRead.GetCount())
            return E_OUTOFMEMORY;

        hr = hInFile.Read(bufRead.GetData(), (DWORD)bufRead.GetCount());
        if (FAILED(hr))
            return hr;

        // 准备压缩
        ULONGLONG uOutFileSize = max(uInFileSize, ZLIB_DECOMPRESS_INIT_BUFF_SIZE);
        CAtlArray<BYTE> bufWrite;
        try
        {
            while (uOutFileSize <= ZLIB_SINGLE_FILE_MAX_SIZE )
            {
                bufWrite.SetCount(0);
                bufWrite.SetCount((DWORD)uOutFileSize);
                if (uOutFileSize != bufWrite.GetCount())
                    return E_OUTOFMEMORY;

                DWORD dwcompressSize = DWORD(uOutFileSize);
                int nRet = zlib_compress2(
                    bufWrite.GetData(),
                    &dwcompressSize,
                    bufRead.GetData(),
                    (int)bufRead.GetCount(),
                    level
                    );
                if (nRet == Z_OK && dwcompressSize <= uOutFileSize)
                {
                    bufWrite.SetCount(dwcompressSize);
                    break;
                }

                if (nRet != Z_BUF_ERROR)
                    return E_FAIL;

                uOutFileSize *= 2;
            }	
        }
        catch (...)
        {
            return E_FAIL;
        }

        hr = hOutFile.Write(bufWrite.GetData(), (DWORD)bufWrite.GetCount());
        if (FAILED(hr))
            return hr;

        return S_OK;
    }
    else
    {
        return E_NOINTERFACE;
    }
}
开发者ID:dreamsxin,项目名称:PcManager,代码行数:93,代码来源:zlibimp.cpp


注:本文中的CAtlFile::Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。