Unicode相关

    技术2022-05-11  75

     CFile cLog;  //日志文件 try {   cLog.Open(_T("log.txt"), CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite); //打开文件  char buff[2];      //Unicode编码时需要写入头部  memset(buff,0,sizeof(buff));  buff[0] = 0xff;  buff[1] = 0xfe;  cLog.Write(&buff,sizeof(buff));     cLog.Seek(sizeof(buff),CFile::begin);

      strMsg = _T("开始/r/n");  cLog.Write(strMsg, sizeof(TCHAR) * strMsg.GetLength()); } catch(CFileException e) {  e.GetErrorMessage(strErr.GetBuffer(255),254);  strErr.ReleaseBuffer();  AfxMessageBox(strErr);  return; }

    //以下是编程时的使用

    m_iWaitTime = _wtoi(strWaitTime);   //字符串转化成数字

    strFilePath = _T("");

    strWaitTime.Format(_T("%d"), m_iWaitTime);    //加上_T()

     

    //INI文件的读写

     ::GetPrivateProfileString(_T("DateBase"),_T("IP"),_T("127.0.0.1"), m_strDBIP.GetBuffer(48), 48 * sizeof(TCHAR),m_strIniPath);  ::GetPrivateProfileString(_T("DateBase"),_T("Name"),_T("sa"), m_strDBUserName.GetBuffer(256),256 * sizeof(TCHAR), m_strIniPath); ::GetPrivateProfileString(_T("DateBase"),_T("Password"),_T(""), m_strDBPwd.GetBuffer(256),256 * sizeof(TCHAR),m_strIniPath);  ::GetPrivateProfileString(_T("DateBase"),_T("DBName"),_T("netocr"),m_strDBName.GetBuffer(256),256 * sizeof(TCHAR),m_strIniPath); CString strWaitTime;  ::GetPrivateProfileString(_T("DateBase"),_T("WaitTime"),_T("3"), strWaitTime.GetBuffer(256),256 * sizeof(TCHAR),m_strIniPath);   m_strDBIP.ReleaseBuffer(); m_strDBName.ReleaseBuffer(); m_strDBPwd.ReleaseBuffer(); m_strDBUserName.ReleaseBuffer();

     m_iWaitTime = _wtoi(strWaitTime); strWaitTime.ReleaseBuffer();

     //写配置文件 ::WritePrivateProfileString(_T("DateBase"),_T("IP"),m_strDBIP,m_strIniPath);  ::WritePrivateProfileString(_T("DateBase"),_T("Name"),m_strDBUserName,m_strIniPath); ::WritePrivateProfileString(_T("DateBase"),_T("Password"),m_strDBPwd,m_strIniPath);  ::WritePrivateProfileString(_T("DateBase"),_T("DBName"),m_strDBName,m_strIniPath); CString strWaitTime; strWaitTime.Format(_T("%d"), m_iWaitTime); ::WritePrivateProfileString(_T("DateBase"),_T("WaitTime"),strWaitTime,m_strIniPath);


    最新回复(0)