/// <summary> /// Retrives the name of the ShellItem. /// </summary> private void SetText() { // reserve memory for an unmanaged STRRET structure // uType -> 4 bytes // union -> MAX_PATH * 2 IntPtr strret = Marshal.AllocCoTaskMem((ShellAPI.MAX_PATH << 1) + 4); // set strret to 0 Marshal.WriteInt32(strret, 0, 0); StringBuilder buf = new StringBuilder(ShellAPI.MAX_PATH); ShellAPI.HRESULT hr; hr = parent.folder.GetDisplayNameOf(relPidl.Ptr, ShellAPI.SHGNO.INFOLDER, strret); if (hr == ShellAPI.HRESULT.S_OK) { ShellAPI.StrRetToBuf(strret, relPidl.Ptr, buf, ShellAPI.MAX_PATH); text = buf.ToString(); } Marshal.FreeCoTaskMem(strret); }