To answer the second part of your question, you need to do something like
LV_DISPINFO dispinfo; dispinfo.item.pszText = LPTSTR((LPCTSTR)string);
since MS LVITEM struct has LPTSTR , i.e. mutable T-string pointer, not LPCTSTR . What you do is
1) convert string (a CString when guessing) to LPCTSTR (which in practice means getting the address of its character buffer as a read-only pointer)
2) convert this read-only pointer to a writable pointer, discarding its const -ness.
It depends on what dispinfo used to see if it is likely that your ListView call will end up trying to write via pszText . If so, this is very dangerous: in the end, you got a read-only pointer, and then decided to treat it as writable: there might be a reason it was read-only!
If this is the CString you are working with, you have the option to use string.GetBuffer() - this intentionally gives you the option to write LPTSTR . Then you need to remember the call to ReleaseBuffer() if the string is changed. Or you can allocate a local temporary buffer and copy the line there.
In 99% of cases this will be superfluous, and processing LPCTSTR as LPTSTR will work ... but one day, when you least expect it ...
AAT Sep 05 2018-11-11T00: 00Z
source share