ShBrowseForFolder & PIDL Memory Freeing

From: AlanGLLoyd (alanglloyd_at_aol.com)
Date: 01/22/04


Date: 22 Jan 2004 07:24:16 GMT

A short while ago the subject of freeing PIDL (Ptr to Id List) memory passed by
ShBrowseForFolder was aired on this NG.

During dialog display a PIDL is also returned by a BFFM_SELCHANGED message to
enable the program to check for selection validity and appropriately enable the
ShBFF dialog's OK button.

However if a selection is OK'ed then the PIDL returned by ShBFF() uses the same
memory as that passed by BFFM_SELCHANGED message.

This supports the assumption that ShBFF() frees the PIDL memory passed by the
BFFM_SELCHANGED message if it is not OK'ed. And also the view that PIDL memory
passed by BFFM_SELCHANGED must NOT be freed.

MSDN says only "The calling application is responsible for freeing the returned
PIDL". Implication is that one should free the PIDL's memory whenever one gets
a PIDL. But with hindsight and the above facts this is not so (and is not
stated by careful reading of MSDN). So memory for the PIDL passed in
BFFM_SELCHANGED must NOT be freed, but that returned later by ShBFF() should
be.

But it is only my assumption that un-OK'ed PIDL memory is freed by ShBFF(). And
if the _program_ should free it if not OK'ed, then it would need some nasty
logic and storage of PIDL values by the program.

Any comments on this would be welcome.

Alan Lloyd
alanglloyd@aol.com


Quantcast