资源介绍
QT版本
//xxxx.h
//log level
#define LL_DEBUG 0
#define LL_INFO 1
#define LL_WARN 2
#define LL_ERROR 3
#define LL_ALARM 4
#define GetCurFileName (__FILE__)
#define GetCurCodeLine (__LINE__)
#define GetCurCodeFunctionName (__FUNCTION__)
#define Write_Log(LEVEL, FMTLOG) WriteLog(LEVEL, FMTLOG, GetCurFileName, GetCurCodeLine, GetCurCodeFunctionName)
void WriteLog(int, QString, QString, int, QString);
//xxxx.cpp
void WriteLog(int loglevel, QString strlogstr, QString strfilename, int iline, QString strfunname)
{
QString g_logdllpath(g_runPath + "/dependences/LoggingModeDLL.dll");
HINSTANCE hDll = LoadLibrary(g_logdllpath.toStdWString().data());
typedef int (__cdecl *MYFUNC)(int, char*, char*, int, char*);
MYFUNC execfunc = (MYFUNC)GetProcAddress(hDll, "WriteLog");
execfunc(loglevel, const_cast(strlogstr.toLatin1().data()),
const_cast(strfilename.toLatin1().data()),
iline,
const_cast(strfunname.toLatin1().data()));
}
MFC 版本
//xxxx.h
//log level
#define LL_DEBUG 0
#define LL_INFO 1
#define LL_WARN 2
#define LL_ERROR 3
#define LL_ALARM 4
#define GetCurFileName (__FILE__)
#define GetCurCodeLine (__LINE__)
#define GetCurCodeFunctionName (__FUNCTION__)
#define Write_Log(LEVEL, FMTLOG) WriteLog(LEVEL, FMTLOG, GetCurFileName, GetCurCodeLine, GetCurCodeFunctionName)
void WriteLog(int, CString, CString, int, CString);
void WriteLog(int loglevel, CString strlogstr, CString strfilename, int iline, CString strfunname)
{
CString g_logdllpath(".\\LoggingModeDLL.dll");
HINSTANCE hDll = LoadLibrary(g_logdllpath.GetBuffer());
typedef int (__cdecl *MYFUNC)(int, char*, char*, int, char*);
MYFUNC execfunc = (MYFUNC)GetProcAddress(hDll, "WriteLog");
execfunc(loglevel,
const_cast(strlogstr.GetBuffer()),
const_cast(strfilename.GetBuffer()),
iline,
const_cast(strfunname.GetBuffer()));
}
- 上一篇: VS2010中调试Qt QString的原生内容显示
- 下一篇: QT中QString类中文详解