win32里好像不能用mfc的类吧?

解决方案 »

  1.   

    你的工程不支持MFC,所以不能用cfile!在project--setting里改
      

  2.   

    我的意思是不使用project--setting的use in mfc
      

  3.   

    CCriticalSection log_lock;  //全局变量
    bool LOG_ERR(char *log_buffer)
    {
      FILE *fp;
      char tmpbuf[1024],cc[10],filename[100];
      struct tm *newtime;
      time_t long_time;

      time( &long_time );                /* Get time as long integer. */
      newtime = localtime( &long_time ); /* Convert to local time. */  sprintf(filename, ".\\log\\%d-%d-%d_err.txt",(newtime->tm_year + 1900),(newtime->tm_mon + 1),newtime->tm_mday );  //下面的操作需要加锁
      log_lock.Lock();  if ( ( fp = fopen(filename,"a+") ) == NULL ) 
      {
        if ( ( fp = fopen(filename,"w+") ) == NULL ) 
        {
          printf("error open log file");
    return -1;
        }
      }
      /* Write Message To The End Of Trace File */
      _strtime(cc);
      sprintf(tmpbuf,"%s--%s\n", cc, buf );
      fputs( tmpbuf, fp);
      /* close trace file */
      fclose( fp );  log_lok.Unlock();
      //完成之后将锁释放掉
    }
      

  4.   

    还是直接用mfc中的文件比较方便,加入mfc的支持,如果代码不太多最好重新做一个,有“应用程序向导”,比较安全,如果你对手动添加mfc不太熟!
      

  5.   

    用下面几个Function了,具体请查阅MSDN
    HANDLE hFile = CreateFile(...);
    BOOL   bRead = ReadFile(hFile,...);
    BOOL   bWrite = WriteFile(hFile,...);
    CloseHandle(hFile);
      

  6.   

    这么麻烦吗,算了,结贴,给分,还是用MFC算了,