Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SHBrowseForFolder

3 views
Skip to first unread message

Andrew Lee-Thorp

unread,
Aug 30, 1999, 3:00:00 AM8/30/99
to
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


Chris Marriott

unread,
Aug 30, 1999, 3:00:00 AM8/30/99
to

Andrew Lee-Thorp wrote in message <7qdvui$23h5$1...@nnrp01.ops.uunet.co.za>...


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 Osborne

unread,
Aug 30, 1999, 3:00:00 AM8/30/99
to
Can't you also just use CoTaskMemFree() to wrap all that up into a single
function?

Todd

Chris Marriott <ch...@NOSPAM.skymap.com> wrote in message
news:936027321.16147.1...@news.demon.co.uk...
>

Chris Marriott

unread,
Aug 30, 1999, 3:00:00 AM8/30/99
to

Todd Osborne wrote in message ...

>Can't you also just use CoTaskMemFree() to wrap all that up into a single
>function?


Probably, yes :-). I just described the way that I do it, but there may well
be better ways!

Alex Blekhman

unread,
Aug 31, 1999, 3:00:00 AM8/31/99
to
It's taken from MSDN article: Shell Namespace

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

0 new messages