您的位置:首页 > 其它

用ATL写文件

2015-09-27 18:17 190 查看
#include "stdafx.h"
#include "Translate.h"
#include <AtlStr.h>
#include <AtlFile.h>
#include <AtlTime.h>

// CTranslate

void writelogA(LPSTR s)
{
try
{
USES_CONVERSION;
CAtlFile oFile;
CTime t = CTime::GetCurrentTime();
CAtlStringA sz;
sz.Format("[%d-%d-%d %d:%d:%d] %s\r\n", t.GetYear(), t.GetMonth(), t.GetDay(), t.GetHour(), t.GetMinute(), t.GetSecond(), s);
CComBSTR tem(sz);
if (oFile.Create(_T("C:\\log\\test.txt"), GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL, NULL) == S_OK)
{
oFile.Seek(0, FILE_END);
oFile.Write(tem, tem.ByteLength());
oFile.Close();
}
}
catch (...)
{
}


}

void writelog(CString cstring)

{
LPSTR   lpwlog;
lpwlog = (LPSTR)(LPCTSTR)cstring;
writelogA(lpwlog);

}

STDMETHODIMP CTranslate::Lnl_InitCommunication()

{
CString cstring("Lnl_InitCommunication");
writelog(cstring);
return S_OK;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: