c++user-interfacewinapimfc

Does the ListView_InsertGroup Win32 API make a deep copy of the LVGROUP::pszHeader member?


Does the ListView_InsertGroup Win32 API make a deep copy of the pszHeader member of the given LVGROUP? The documentation for ListView_InsertGroup or LVGROUP does not state this, nor does it state what is the required lifetime of the buffer holding the LVGROUP::pszHeader member. I need to know whether the buffer containing the LVGROUP::pszHeader bytes needs to outlive the ListView_InsertGroup call.

Note that the pszHeader strings cannot be a literal like is shown in examples. The header string is loaded from a file and cannot be hard-coded.

The same can be asked of the MFC CListCtrl::InsertGroup API.


Solution

  • The text is deep-copied. This is not explicitly stated in the documentation, but it is implied:

    LVGROUP structure (commctrl.h)

    pszHeader

    Type: LPWSTR

    Pointer to a null-terminated string that contains the header text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the header text.

    Retrieving the text requires the caller to provide a destination buffer where the text will be copied into, which means the ListView must store the text somewhere in order to copy from it.

    The same thinking applies to the pszFooter, pszSubtitle, pszTask, pszDescriptionTop, pszDescriptionBottom, and pszSubsetTitle fields as well.