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

Emile Cormier (Corel) 25 Reputation points
2025-08-18T23:43:13.0533333+00:00

Does the ListView_InsertGroup Win32 API make a deep copy of the LVGROUP::pszHeader member? 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 header strings are not literals, but are loaded from a file and cannot be hard-coded.

Windows development | Windows API - Win32
0 comments No comments
{count} votes

Answer accepted by question author
  1. RLWA32 51,536 Reputation points
    2025-08-19T07:07:42.4233333+00:00

    The List View control makes a copy of the string whose address is assigned to the LVGROUP pszHeader member.

    You can empirically determine this is the case by using a debugger to change the string value pointed to by pszHeader during execution. If the List View control only stored the pointer value then those subsequent changes would be reflected in the control during execution, but they are not.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Ziad weam 0 Reputation points
    2025-08-19T00:12:30.0866667+00:00

    The ListView_InsertGroup function in the Win32 API does not perform a deep copy of the LVGROUP::pszHeader member. It stores the pointer to the string as provided in the LVGROUP structure. Therefore, the memory holding the pszHeader string must be valid for as long as the group is present in the list view.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.