Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Freeing IMalloc allocation from managed code

Status
Not open for further replies.

JCARPENTER

Programmer
Mar 30, 2000
8
US
I have a class that allows me to browse folders. It uses unmanaged code in shell32.dll. Everything works, but I can't figure out how to call IMalloc::Free() from C#. I've included the class below. The commented section is the equivalent C++ code that's the problem. Can anybody help?

Thanks,
Jim

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace BrowseFolder
{
[StructLayout(LayoutKind.Sequential)]
public struct BROWSEINFOW
{
public int hwndOwner;
public IntPtr pidlRoot;
public string lpszDisplayName;
public string lpszTitle;
public uint ulFlags;
public IntPtr lpfn;
public long lParam;
public int iImage;
}

public class MyBrowse
{
[DllImport("Shell32")]
static public extern IntPtr
SHBrowseForFolder(ref BROWSEINFOW BrowseInfo);

[DllImport("Shell32")]
static public extern int
SHGetPathFromIDList(IntPtr pidl,
StringBuilder FolderName);

[DllImport("Shell32")]
static public extern int
SHGetMalloc(ref IntPtr ppMalloc);

static public string BrowseFolders(string title)
{
BROWSEINFOW bi = new BROWSEINFOW();
bi.lpszTitle = title;
IntPtr pItemList = SHBrowseForFolder(ref bi);

if ( pItemList == IntPtr.Zero )
return null;
StringBuilder folder = new StringBuilder(260);
int BOOL = SHGetPathFromIDList(pItemList,folder);

/* This is what I can't figure out
LPMALLOC ppMalloc;
SHGetMalloc(&ppMalloc);
ppMalloc->Free(pItemList);
*/

return folder.ToString();
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top