20140629:简单的打印函数执行日志的函数代码WriteLog函数(适用于c++builder等,未加载lib文件)
2014-06-29 16:49
337 查看
#include<windows.h> #include<FSTREAM> #include<stdio.h> #include<tchar.h> #include<process.h> using namespace std; char pLogPath[1000]; char pCurrentDirectory[1000]; int WriteLog(const char *format, ... ); bool MakeGlobalPath(); bool execwait(char *cmdline,char *cmd,int timeout); int WriteLog(const char *format, ... ) //if succeeds,return 0.else return 1. { MakeGlobalPath(); strcat(pLogPath,"SQLSelect.txt"); FILE *fStream = fopen(pLogPath,"a+"); if (fStream != NULL) { try{ va_list ap; TCHAR strTemp[5120]; va_start(ap,format); vsprintf(strTemp,format,ap); fprintf(fStream,"%s\n",strTemp); va_end(ap); } catch (...) { } fclose(fStream); fStream = NULL; return 0; } else { return 1; } } bool MakeGlobalPath() { char lpModuleFilePath[1000]; DWORD dwModuleFilePath = 0; DWORD iIndex = 0; DWORD iPosition = 0; memset(lpModuleFilePath,0,sizeof(char)*1000); memset(pCurrentDirectory,0,sizeof(char)*1000); dwModuleFilePath = GetModuleFileName(NULL,lpModuleFilePath,1000); //get the exe program's full path name for (;iIndex<dwModuleFilePath;iIndex++) { if (lpModuleFilePath[iIndex]=='\\') { iPosition = iIndex; //get the last blackslash } } strncpy(pCurrentDirectory,lpModuleFilePath,iPosition+1); pCurrentDirectory[iPosition+1] = '\0'; //null strcpy(pLogPath,pCurrentDirectory); //cout<<"pCurrentDirectory"<<pCurrentDirectory<<endl<<"pLogPath"<<pLogPath<<endl; return true; } bool execwait(char *cmdline,char *cmd,int timeout) { PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory( &pi, sizeof(pi) ); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; CreateProcess(cmdline,cmd,NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); WaitForSingleObject(pi.hProcess ,timeout); //Edit1->Text = "ddd"; CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); return true; }
相关文章推荐
- 简单实用的打印函数执行日志的代码WriteLog函数
- 简单的程序日志打印函数WriteLog,适用于vc等,含宽字符。
- 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码。
- 一个简单的用于嵌入式Linux开发的C调试日志打印接口
- js 加载过后正确地执行函数.
- 在onload上加载执行多个函数
- 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起
- 一个打印日志函数
- 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起。
- XAML加载情况判断并延时执行函数
- 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起。
- 简单的小九九打印函数
- 一个简单用C语言实现的日志函数
- 调试信息的宏定义:能够打印出文件名、函数、行数、日志,方便调试
- 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码
- 一个简单用C语言实现的日志函数
- javascript 等待几秒钟以后执行特定函数 简单timer使用法
- 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码...
- 检测到LoaderLock,正试图在OS加载程序锁内执行托管代码,不要尝试在DllMain或映像初始化函数内运行托管代码,这样会导致应用程序挂起。
- linux 下 打印日志函数