用ATL写文件

来源:互联网 发布:社交软件的普遍性 编辑:程序博客网 时间:2024/06/15 14:34
#include "stdafx.h"#include "Translate.h"#include <AtlStr.h>#include <AtlFile.h>#include <AtlTime.h>// CTranslatevoid 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;
}
0 0
原创粉丝点击