The documentation says:"The calling application is responsible for freeing
the returned item identifier list by using the shell's task allocator".
Any ideas on how to free the ITEMIDLIST.
Andrew
1. Call "SHGetMalloc" to get a pointer to the shell's "IMalloc" memory
allocator interface.
2. Call the allocator's "Free" function to free the memory.
3. Call the allocator's "Release" function to unload it.
Regards,
Chris
-----------------------------------------------------------------------
Chris Marriott, SkyMap Software, UK (ch...@skymap.com)
Visit our web site at http://www.skymap.com
Astronomy software written by astronomers, for astronomers
Todd
Chris Marriott <ch...@NOSPAM.skymap.com> wrote in message
news:936027321.16147.1...@news.demon.co.uk...
>
Probably, yes :-). I just described the way that I do it, but there may well
be better ways!
Browsing for Folders
The following example uses the SHBrowseForFolder function to prompt the user
for a program group. The Programs directory is specified as the root.
// Main_OnBrowse - browses for a program folder.
// hwnd - handle to the application's main window.
//
// Uses the global variable g_pMalloc, which is assumed to point
// to the shell's IMalloc interface.
void Main_OnBrowse(HWND hwnd)
{
BROWSEINFO bi;
LPSTR lpBuffer;
LPITEMIDLIST pidlPrograms; // PIDL for Programs folder
LPITEMIDLIST pidlBrowse; // PIDL selected by user
// Allocate a buffer to receive browse information.
if ((lpBuffer = (LPSTR) g_pMalloc->lpVtbl->Alloc(
g_pMalloc, MAX_PATH)) == NULL)
return;
// Get the PIDL for the Programs folder.
if (!SUCCEEDED(SHGetSpecialFolderLocation(
hwnd, CSIDL_PROGRAMS, &pidlPrograms))) {
g_pMalloc->lpVtbl->Free(g_pMalloc, lpBuffer);
return;
}
// Fill in the BROWSEINFO structure.
bi.hwndOwner = hwnd;
bi.pidlRoot = pidlPrograms;
bi.pszDisplayName = lpBuffer;
bi.lpszTitle = "Choose a Program Group";
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;
// Browse for a folder and return its PIDL.
pidlBrowse = SHBrowseForFolder(&bi);
if (pidlBrowse != NULL) {
// Show the display name, title, and file system path.
MessageBox(hwnd, lpBuffer, "Display name", MB_OK);
if (SHGetPathFromIDList(pidlBrowse, lpBuffer))
SetWindowText(hwnd, lpBuffer);
// Free the PIDL returned by SHBrowseForFolder.
g_pMalloc->lpVtbl->Free(g_pMalloc, pidlBrowse);
}
// Clean up.
g_pMalloc->lpVtbl->Free(g_pMalloc, pidlPrograms);
g_pMalloc->lpVtbl->Free(g_pMalloc, lpBuffer);
}
How to get g_pMalloc:
Call the SHGetMalloc() function to get the IMalloc interface pointer to the
shell's task allocator. Once you have that pointer call IMalloc::Free()
passing the LPITEMIDLIST pointer returned from SHBrowseForFolder().
Andrew Lee-Thorp wrote:
>
> SHBrowseForFolder returns an PITEMIDLIST.
>
> The documentation says:"The calling application is responsible for freeing
> the returned item identifier list by using the shell's task allocator".
>
> Any ideas on how to free the ITEMIDLIST.
>
> Andrew