?? timelogserver.cpp
字號:
#include "stdafx.h"
#include "TimeLogServerApp.h"
#include "TimeLogServer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTimeLogServer
IMPLEMENT_DYNCREATE(CTimeLogServer, CCmdTarget)
CTimeLogServer::CTimeLogServer()
{
EnableAutomation();
::AfxOleLockApp();
CTime TimeStamp = CTime::GetCurrentTime();
CString FileName;
FileName.Format(_T("%s.log"),TimeStamp.Format("%Y%m%d"));
m_logfile = fopen(FileName,_T("a"));
if(m_logfile)
{
fprintf(m_logfile,_T("# # # # # # # # # # # # # # # # # \n"));
fprintf(m_logfile,_T("開始于:%s"),(LPCTSTR)TimeStamp.Format("%Y年%m月%d日%H:%M %S"));
fprintf(m_logfile,_T("\n"));
}
}
CTimeLogServer::~CTimeLogServer()
{
::AfxOleUnlockApp();
// 關閉文件
if(m_logfile)
{
CTime TimeStamp = CTime::GetCurrentTime();
fprintf(m_logfile,_T("\n"));
fprintf(m_logfile,_T("結束于:%s"),(LPCTSTR)TimeStamp.Format("%Y年%m月%d日%H:%M %S"));
fprintf(m_logfile,_T("\n"));
fprintf(m_logfile,_T("# # # # # # # # # # # # # # # # #\n"));
fclose(m_logfile);
}
}
void CTimeLogServer::OnFinalRelease()
{
// When the last reference for an automation object is released
// OnFinalRelease is called. The base class will automatically
// deletes the object. Add additional cleanup required for your
// object before calling the base class.
CCmdTarget::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(CTimeLogServer, CCmdTarget)
//{{AFX_MSG_MAP(CTimeLogServer)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CTimeLogServer, CCmdTarget)
//{{AFX_DISPATCH_MAP(CTimeLogServer)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_ITimeLogServer to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {DB38AC5C-B40C-4968-A1BA-904EC70D6809}
/*static const IID IID_ITimeLogServer =
{ 0xdb38ac5c, 0xb40c, 0x4968, { 0xa1, 0xba, 0x90, 0x4e, 0xc7, 0xd, 0x68, 0x9 } };
BEGIN_INTERFACE_MAP(CTimeLogServer, CCmdTarget)
INTERFACE_PART(CTimeLogServer, IID_ITimeLogServer, Dispatch)
END_INTERFACE_MAP()
*/
//實現類廠
IMPLEMENT_OLECREATE(CTimeLogServer,"TimeLogServer",
0x55aa866, 0x1260, 0x4633, 0x86, 0x9, 0x4, 0xca, 0xed, 0x21, 0xb0, 0xb);
//映射接口到相應的嵌套類
BEGIN_INTERFACE_MAP(CTimeLogServer,CCmdTarget)
INTERFACE_PART(CTimeLogServer,IID_ITimeLog,TimeLog)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTimeLogServer message handlers
//為嵌套類而實現IUnknown接口
STDMETHODIMP_(ULONG)
CTimeLogServer::XTimeLog::AddRef()
{
METHOD_PROLOGUE(CTimeLogServer,TimeLog)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG)
CTimeLogServer::XTimeLog::Release()
{
METHOD_PROLOGUE(CTimeLogServer,TimeLog)
return pThis->ExternalRelease();
}
STDMETHODIMP
CTimeLogServer::XTimeLog::QueryInterface(REFIID riid,void** ppvObj)
{
METHOD_PROLOGUE(CTimeLogServer,TimeLog)
return pThis->ExternalQueryInterface(&riid,ppvObj);
}
STDMETHODIMP
CTimeLogServer::XTimeLog::OutputLog(BSTR* varLogText)
{
METHOD_PROLOGUE(CTimeLogServer,TimeLog)
if(pThis->m_logfile)
{
CTime TimeStamp = CTime::GetCurrentTime();
CString NowTime = TimeStamp.Format("%Y年%m月%d日%H:%M:%S");
CString LogText((LPCWSTR)*varLogText);
fprintf(pThis->m_logfile,"\n%s\n%s\n%",NowTime,LogText);
return NOERROR;
}
else
{
AfxMessageBox("沒有日志文件!");
return S_FALSE;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -