This will never work as expected.
You are storing the string in
m_strParamval
. This string will be updated whenever you insert a new item. So you would always get the string for the last added item.
But more important, the
LPARAM
values might not point to a valid string anymore.
m_strParamval
is of type
CString
which might allocate new memory when assigning a new string that is larger than the existing content. Then the pointer returned by
CString::GetString()
(which is used when assigning a
CString
to a
LPCTSTR
) is not valid anymore.
If you want to store individual strings for each item you have to use allocated memory for each item and free that when items are removed and the tree is destroyed.
Example:
CString strParamval = _T("LENG") + CXString::Format(_T("%d"), m_nMatID);
TCHAR *pszParamVal = new TCHAR[strParamval.GetLength()];
_tcscpy(pszParamVal, strParamval.GetString());
Again: When doing so, don't forget to delete the memory when deleting items or destroying the tree control.