PRINT_LOG("CRespMsgInfo","SetRspMsgInfo","rev right msg 0x%x",m_ulResponseMsgId);PRINT_LOG("CRespMsgInfo","SetRspMsgInfo","%s","rev right msg 0x%x",m_ulResponseMsgId);结果是:第一行 打印 会根据 m_ulResponseMsgId 打印出一个16进制的值.  第二行 貌似无论m_ulResponseMsgId 的值是神马,很多时候打印出的是一个固定的值,但有时候又打印出的貌似不一样,糊涂了下面附代码类型 UINT32 m_ulResponseMsgId;  void PrintLog(const char * szModule, const char * szTitle,const char * format, ...)
{
//多线程保护
HANDLE m_eventNoReaders;
static CRITICAL_SECTION m_csLockLog;
static int flag=0;
if (0 == flag)
{
InitializeCriticalSection(&m_csLockLog);
flag = 1;
}CMYCriticalSection lock(&m_csLockLog, TRUE);va_list argp;
va_start(argp, format);
DoPrintLog(szModule, szTitle, format, argp);
va_end(argp);   
}
static void DoPrintLog( const char * szModule,  
  const char * szTitle,  
  const char * format,  
  va_list argp)
{
//static FILE* g_logFile = NULL;SYSTEMTIME st;
GetLocalTime(&st);
    
if (NULL==g_logFile)
  {
  char szTmp[1500] = {0};  //sprintf_s(szTmp,_countof(szTmp),"%s%s",GetAppPath(),"log.txt");
// dkf40287 20110216 加上时间戳
sprintf_s(szTmp,sizeof(szTmp),"%s%s%04d-%02d-%02d-%02d-%02d%s",GetAppPath(),"log-",st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,".txt");
  g_logFile =::_fsopen(szTmp, "w",_SH_DENYNO);
  }  memset(m_szMsg, 0, sizeof(m_szMsg));
  //添加信息头//日期时间 dkf40287 20110216
  //SYSTEMTIME st;
  //GetLocalTime(&st);
  sprintf_s(m_szMsg, sizeof(m_szMsg), "[%02d-%02d %02d:%02d:%02d.%03d][%s][%s]",st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds,szModule,szTitle);  //添加信息体
  /*_vsnprintf(&m_szMsg[strlen(m_szMsg)], MAX_LOG_LENGTH-strlen(m_szMsg)-strlen(LOG_END_FLAG),  
  format, argp);*/
_vsnprintf_s(&m_szMsg[strlen(m_szMsg)], sizeof(m_szMsg) - strlen(m_szMsg), _TRUNCATE,format, argp);fprintf(g_logFile, m_szMsg);
fprintf(g_logFile, "\n");   
fflush(g_logFile);   

 
 
 
对我有用[0] 丢个板砖[0] 引用 举报 管理 TOP 回复次数:4  

解决方案 »

  1.   

    楼主这样试试PRINT_LOG("CRespMsgInfo","SetRspMsgInfo","%srev right msg 0x%x", "**TEST**", 1024);
      

  2.   

    // variable_argument_lists.cpp
    #include <stdio.h>
    #include <stdarg.h>//  Declaration, but not definition, of ShowVar.
    void ShowVar( char *szTypes, ... );
    int main() {
       ShowVar( "fcsi", 32.4f, 'a', "Test string", 4 );
    }//  ShowVar takes a format string of the form
    //   "ifcs", where each character specifies the
    //   type of the argument in that position.
    //
    //  i = int
    //  f = float
    //  c = char
    //  s = string (char *)
    //
    //  Following the format specification is a list
    //  of n arguments, where n == strlen( szTypes ).
    void ShowVar( char *szTypes, ... ) {
       va_list vl;
       int i;   //  szTypes is the last argument specified; all
       //   others must be accessed using the variable-
       //   argument macros.
       va_start( vl, szTypes );   // Step through the list.
       for( i = 0; szTypes[i] != '\0'; ++i ) {
          union Printable_t {
             int     i;
             float   f;
             char    c;
             char   *s;
          } Printable;      switch( szTypes[i] ) {   // Type to expect.
             case 'i':
                Printable.i = va_arg( vl, int );
                printf_s( "%i\n", Printable.i );
             break;         case 'f':
                 Printable.f = va_arg( vl, double );
                 printf_s( "%f\n", Printable.f );
             break;         case 'c':
                 Printable.c = va_arg( vl, char );
                 printf_s( "%c\n", Printable.c );
             break;         case 's':
                 Printable.s = va_arg( vl, char * );
                 printf_s( "%s\n", Printable.s );
             break;         default:
             break;
          }
       }
       va_end( vl );
    }
      

  3.   

    看看printf()的定义http://blog.csdn.net/fengrx/archive/2009/04/29/4135090.aspx
      

  4.   

    “....”代表这个函数还可以有一个或者多个“....”之前出现的参数类型一样的参数,比如GetString(CString A,CString B,...),你在调用这个函数的时候,比如GetString(str1,str2),或者GetString(str1,sr2,str3)或者GetString(str1,str2,str3,str4)...只要里边的参数都是CString的就行了。
      

  5.   

    PRINT_LOG("CRespMsgInfo","SetRspMsgInfo","%s","rev right msg 0x%x",m_ulResponseMsgId);
    看样子是要有两个变量输入,而你只有一个m_ulResponseMsgId被输入了,还差个。