Click here to Skip to main content
15,895,142 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Some ambiguities with MFC CString class. Pin
John R. Shaw7-Sep-07 22:07
John R. Shaw7-Sep-07 22:07 
GeneralRe: Some ambiguities with MFC CString class. [modified] Pin
Hamed Musavi8-Sep-07 4:08
Hamed Musavi8-Sep-07 4:08 
AnswerRe: Some ambiguities with MFC CString class. Pin
bob169728-Sep-07 4:36
bob169728-Sep-07 4:36 
GeneralRe: Some ambiguities with MFC CString class. Pin
Hamed Musavi8-Sep-07 4:41
Hamed Musavi8-Sep-07 4:41 
GeneralRe: Some ambiguities with MFC CString class. Pin
progDes8-Sep-07 6:05
progDes8-Sep-07 6:05 
GeneralRe: Some ambiguities with MFC CString class. Pin
Hamed Musavi8-Sep-07 18:45
Hamed Musavi8-Sep-07 18:45 
AnswerRe: Some ambiguities with MFC CString class. Pin
Mark Salsbery8-Sep-07 6:42
Mark Salsbery8-Sep-07 6:42 
GeneralRe: Some ambiguities with MFC CString class. Pin
Hamed Musavi8-Sep-07 9:04
Hamed Musavi8-Sep-07 9:04 
Thanks for your reply Mark. I have recently many question answered by you. You deserve being a CP MVP, if you are not already.


Mark Salsbery wrote:
You haven't initialized the array that's being copied to the CString.


Actually I did. I hope you are patient enough to read this similar to real code:

For easier reading I ignored .h and .cpp and wrote them at once.
Class a
{
  void SetPath(CString strPath)
  {
    memset(m_pA->pSzPath, NULL, MAX_PATH);

    int len = min(MAX_PATH, strPath.GetLength());
    strncpy(m_pA->pSzPath, strPath, len);  // Path to folder
    m_pA->bPathUpdated = TRUE;  // a volatile BOOL
  }

  static UINT ThumbnailViewerThread(LPVOID pParam)
  {
    CString strFullPath, strFileName, strFolderPath;
    // blah blah
    
    while(!pData->bStop)
    {
      if (pClientData->bPathUpdated)
      {

        // Find file name by enumerating the folder

        // Replace the following 2 lines, every thing's fine! no need to Empty()

        // strFolderPath = _T("C:\\Images");
        strFolderPath = pClientData->pSzPath; // Folder path

        strFullPath = strFolderPath + "\\" + strFileName;
        // Blah blah

        // Memory leak, if I comment the following
        strFolderPath.Empty();
      }
      else
      {
         sleep(500);
      }
    }    
  }
}


I call SetPath member function to set a new path for the thumbnail thread reader.



// "Life is very short and is very fragile also." Yanni
while (I'm_alive)
{
cout<<"I love programming.";
}

GeneralRe: Some ambiguities with MFC CString class. Pin
Mark Salsbery8-Sep-07 10:59
Mark Salsbery8-Sep-07 10:59 
GeneralRe: Some ambiguities with MFC CString class. Pin
Hamed Musavi8-Sep-07 15:53
Hamed Musavi8-Sep-07 15:53 
GeneralRe: Some ambiguities with MFC CString class. Pin
Mark Salsbery9-Sep-07 6:51
Mark Salsbery9-Sep-07 6:51 
GeneralRe: Some ambiguities with MFC CString class. Pin
Hamed Musavi9-Sep-07 18:11
Hamed Musavi9-Sep-07 18:11 
QuestionSOLVED: MFC: document-view problem [modified] Pin
progDes7-Sep-07 18:41
progDes7-Sep-07 18:41 
AnswerRe: MFC: document-view problem Pin
chandu0047-Sep-07 19:39
chandu0047-Sep-07 19:39 
GeneralRe: MFC: document-view problem Pin
progDes7-Sep-07 20:02
progDes7-Sep-07 20:02 
QuestionTreeview Question Pin
simotix7-Sep-07 17:00
simotix7-Sep-07 17:00 
AnswerRe: Treeview Question Pin
Michael Dunn7-Sep-07 17:24
sitebuilderMichael Dunn7-Sep-07 17:24 
GeneralRe: Treeview Question Pin
simotix7-Sep-07 19:04
simotix7-Sep-07 19:04 
GeneralRe: Treeview Question Pin
Michael Dunn7-Sep-07 20:06
sitebuilderMichael Dunn7-Sep-07 20:06 
GeneralRe: Treeview Question Pin
simotix8-Sep-07 6:49
simotix8-Sep-07 6:49 
QuestionC question, can't free string from a struct Pin
gizmokaka7-Sep-07 15:06
gizmokaka7-Sep-07 15:06 
AnswerRe: C question, can't free string from a struct Pin
Leslie Sanford7-Sep-07 15:28
Leslie Sanford7-Sep-07 15:28 
GeneralRe: C question, can't free string from a struct Pin
gizmokaka7-Sep-07 21:51
gizmokaka7-Sep-07 21:51 
AnswerRe: C question, can't free string from a struct Pin
John R. Shaw7-Sep-07 17:30
John R. Shaw7-Sep-07 17:30 
GeneralRe: C question, can't free string from a struct Pin
gizmokaka7-Sep-07 22:01
gizmokaka7-Sep-07 22:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.