MFC CString reads the configuration file path string with the direct assignment paths lead to different results of the reading solution

Case are as follows:

Method a: reading the configuration file from the path

  GetPrivateProfileString("parameter", "sourcefacespath", "NULL", strWindow.GetBuffer(1024), 1024, m_inipath);    

  //strWindow.ReleaseBuffer(1024); // add this one also get the file path in less than
  CString m_folderPath = strWindow; 

CString strWildCard =m_folderPath ;

strWildCard += "\\*.*";

Method two: direct assignment

CString m_folderPath ="\\\\192.168.1.132\\Users\\ZJS\\Desktop\\facesSample"; 

CString strWildCard =m_folderPath ;

strWildCard += "\\*.*";

 

The result: two methods can get the file from the path, and the method can not be;

 

Solution:

GetPrivateProfileString("parameter", "sourcefacespath", "NULL", strWindow.GetBuffer(1024), 1024, m_inipath);    

  strWindow.ReleaseBuffer (); // can not add the data length of brackets

 

Cause Analysis:

GetPrivateProfileString string length required for reading the profile string data, string length specified and often are greater than the actual length of the string, causing the string following problems when splicing, it is necessary to manually release the extra space characters (call ReleaseBuffer () method releases, junction brackets cut length data can be added, otherwise invalid)

These are their stories, and simple to understand, no in-depth research purposes, but want to experience the same situation peers can help.

There is something wrong, welcome specified, grateful!

Published 15 original articles · won praise 20 · views 10000 +

Guess you like

Origin blog.csdn.net/ZDT_zdh/article/details/100113504