Click here to Skip to main content
15,904,415 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: Some ambiguities with MFC CString class. Pin
Mark Salsbery8-Sep-07 10:59
Mark Salsbery8-Sep-07 10:59 
Hamed Mosavi wrote:
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
}


There still may be a problem with the string termination, possibly causing memory corruption or overrun.

Assuming the size of the pSzPath is MAX_PATH, maybe try:
void SetPath(CString strPath)
  {
    memset(m_pA->pSzPath, 0, MAX_PATH);

    int len = min(MAX_PATH<font color="Red"> - 1</font>, strPath.GetLength());
    strncpy(m_pA->pSzPath, strPath, len);  // Path to folder
<font color="Red"><font><font>    m_pA->pSzPath</font></font>[len] = 0;</font>
<font>    m_pA->bPathUpdated = TRUE;  // a volatile BOOL
  }</font>
You shouldn't need the empty call unless you want to explicitly empty the string.

Mark





Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

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 
GeneralRe: C question, can't free string from a struct Pin
John R. Shaw7-Sep-07 22:34
John R. Shaw7-Sep-07 22:34 

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.