public static string StrRetToBuf(ref STRRET pstr, PIDLIST pidl) { var sb = new StringBuilder(MAX_PATH); StrRetToBuf(ref pstr, pidl, sb, sb.Capacity); return(sb.ToString()); }
public static HRESULT StringToStrRet(string pszName, out STRRET pStrRet) { pStrRet = new STRRET { uType = STRRET_TYPE.STRRET_WSTR, pOleStr = Marshal.StringToCoTaskMemUni(pszName) }; return(HRESULT.S_OK); }
public IntPtr GetDisplayName(SIGDN sigdnName) { if (sigdnName == SIGDN.FILESYSPATH) { StringBuilder result = new StringBuilder(512); if (!Shell32.SHGetPathFromIDList(m_Pidl, result)) { throw new ArgumentException(); } return(Marshal.StringToHGlobalUni(result.ToString())); } else { IShellFolder parentFolder = GetParent().GetIShellFolder(); IntPtr childPidl = Shell32.ILFindLastID(m_Pidl); StringBuilder builder = new StringBuilder(512); STRRET strret = new STRRET(); parentFolder.GetDisplayNameOf(childPidl, (SHGNO)((int)sigdnName & 0xffff), out strret); ShlWapi.StrRetToBuf(ref strret, childPidl, builder, (uint)builder.Capacity); return(Marshal.StringToHGlobalUni(builder.ToString())); } }
public static extern Int32 StrRetToBuf( ref STRRET pstr, // Pointer to the STRRET structure. When the function returns, this pointer will no // longer be valid. IntPtr pidl, // Pointer to the item's ITEMIDLIST structure. StringBuilder pszBuf, // Buffer to hold the display name. It will be returned as a null-terminated // string. If cchBuf is too small, the name will be truncated to fit. UInt32 cchBuf); // Size of pszBuf, in characters. If cchBuf is too small, the string will be
public static unsafe HRESULT StrRetToBuf(ref STRRET pstr, IntPtr pidl, Span <char> pszBuf) { fixed(STRRET *pstrLocal = &pstr) { fixed(char *pszBufLocal = pszBuf) { return(StrRetToBuf(pstrLocal, (ITEMIDLIST *)pidl, new PWSTR(pszBufLocal), (uint)pszBuf.Length)); } } }
public IntPtr MarshalManagedToNative(object ManagedObj) { if (!(ManagedObj is string s)) { throw new InvalidCastException(); } var sr = new STRRET { uType = STRRET_TYPE.STRRET_WSTR }; sr.pOleStr.Assign(s); return(sr.StructureToPtr(Marshal.AllocCoTaskMem, out var _)); }
/// <summary> /// Retrieves the display name for the specified file object or subfolder. /// Return value: error code, if any /// </summary> /// <param name="pidl">Address of an ITEMIDLIST structure (PIDL) that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="uFlags">Flags used to request the type of display name to return. For a list of possible values.</param> /// <param name="pName">Address of a STRRET structure in which to return the display name.</param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> int IShellFolder.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { // If we have an invalid PIDL, we must fail. if (pidl == IntPtr.Zero) { pName = new STRRET(); return(WinError.E_INVALIDARG); } // Create an idlist from the pidl. var idlist = PidlManager.PidlToIdlist(pidl); // Get the shell item. // TODO; handle errors var shellItem = GetChildItem(idlist); // If the flags are normal only, we're asking for the display name only. if (uFlags == SHGDNF.SHGDN_NORMAL) { // We only need the display name. pName = STRRET.CreateUnicode(shellItem.GetDisplayName(DisplayNameContext.OutOfFolder)); return(WinError.S_OK); } // If the flags are in folder, we're asking for the standard display name. if (uFlags == SHGDNF.SHGDN_INFOLDER || uFlags == SHGDNF.SHGDN_FORADDRESSBAR) { pName = STRRET.CreateUnicode(shellItem.GetDisplayName(DisplayNameContext.Normal)); return(WinError.S_OK); } // If the flags indicate parsing mode, we need to construct a name // that'll let us bounce from PIDL <-> name. We do this, rather than // the implementor. if (uFlags.HasFlag(SHGDNF.SHGDN_FORPARSING)) { // It's either relative (INFOLDER) or fully qualified. var str = uFlags.HasFlag(SHGDNF.SHGDN_INFOLDER) ? idlist.ToParsingString() : /* TODO start with my id list */ idlist.ToParsingString(); pName = STRRET.CreateUnicode(str); return(WinError.S_OK); } pName = STRRET.CreateUnicode(string.Empty); return(WinError.S_OK); }
public IntPtr GetDisplayName(SIGDN sigdnName) { if (sigdnName == SIGDN.FILESYSPATH) { var result = new StringBuilder(512); if (!Shell32.SHGetPathFromIDList(Pidl, result)) throw new ArgumentException(); return Marshal.StringToHGlobalUni(result.ToString()); } else { IShellFolder parentFolder = GetParent().GetIShellFolder(); IntPtr childPidl = Shell32.ILFindLastID(Pidl); var builder = new StringBuilder(512); var strret = new STRRET(); parentFolder.GetDisplayNameOf(childPidl, (SHGNO)((int)sigdnName & 0xffff), out strret); ShlWapi.StrRetToBuf(ref strret, childPidl, builder, (uint)builder.Capacity); return Marshal.StringToHGlobalUni(builder.ToString()); } }
public static extern string StrRetToStr(ref STRRET pstr, [Optional] IntPtr pidl);
public static extern Int32 StrRetToBSTR( ref STRRET pstr, // Pointer to a STRRET structure. IntPtr pidl, // Pointer to an ITEMIDLIST uniquely identifying a file object or subfolder relative // to the parent folder. [MarshalAs(UnmanagedType.BStr)] out String pbstr); // Pointer to a variable of type BSTR that contains the converted string.
public static extern Int32 StrRetToBSTR( ref STRRET pstr, // Pointer to a STRRET structure. IntPtr pidl, // Pointer to an ITEMIDLIST uniquely identifying a file object or subfolder relative // to the parent folder. [MarshalAs(UnmanagedType.BStr)] out String pbstr);
public static extern Int32 StrRetToBuf( ref STRRET pstr, // Pointer to the STRRET structure. When the function returns, this pointer will no // longer be valid. IntPtr pidl, // Pointer to the item's ITEMIDLIST structure. StringBuilder pszBuf, // Buffer to hold the display name. It will be returned as a null-terminated // string. If cchBuf is too small, the name will be truncated to fit. UInt32 cchBuf);
private static extern int StrRetToBSTR(STRRET pstr, PITEMID_CHILD pidl, [MarshalAs(UnmanagedType.BStr)] out string pbstr);
� � // Accepts a STRRET structure returned by IShellFolder::GetDisplayNameOf that contains or points to a � � // string, and then returns that string as a BSTR. � � // <param> � � // Pointer to a STRRET structure. � � // Pointer to an ITEMIDLIST uniquely identifying a file object or subfolder relative � � // Pointer to a variable of type BSTR that contains the converted string. � � //</param> � � public static extern int StrRetToBSTR(ref STRRET pstr, IntPtr pidl, [MarshalAs(UnmanagedType.BStr)]ref string pbstr);
int IShellFolder2.GetDetailsOf(IntPtr pidl, uint iColumn, out SHELLDETAILS psd) { // Get the folder view columns. var columns = ((DefaultNamespaceFolderView)lazyFolderView.Value).Columns; // If details are being requested for a column we don't have, we must fail. if (iColumn >= columns.Count) { psd = new SHELLDETAILS { cxChar = 0, fmt = 0, str = new STRRET { uType = STRRET.STRRETTYPE.STRRET_WSTR, data = IntPtr.Zero } }; return(WinError.E_FAIL); } // If we have no pidl, we need the details of the column itself. if (pidl == IntPtr.Zero) { var column = columns[(int)iColumn]; // Create the column format. int format = 0; switch (column.ColumnAlignment) { case ColumnAlignment.Left: format = (int)LVCFMT.LVCFMT_LEFT; break; case ColumnAlignment.Centre: format = (int)LVCFMT.LVCFMT_CENTER; break; case ColumnAlignment.Right: format = (int)LVCFMT.LVCFMT_RIGHT; break; default: throw new ArgumentOutOfRangeException(); } // Set the column icon flag (if we have one). if (column.HasImage) { format |= (int)LVCFMT.LVCFMT_COL_HAS_IMAGES; } // TODO I have no idea why the shell details are not correctly respecting the cxChar.. // Create shell details for the column. psd = new SHELLDETAILS { fmt = format, cxChar = column.Name.Length, str = STRRET.CreateUnicode(column.Name) }; } else { // We've been asked for the details of an item. // Get the column ID. PROPERTYKEY propertyKey; ((IShellFolder2)this).MapColumnToSCID(iColumn, out propertyKey); // Get the value of an item at a column. var valueText = GetItemColumnValue(pidl, propertyKey); psd = new SHELLDETAILS { fmt = 0, // todo, currently set to 'left'. cxChar = valueText.Length, str = STRRET.CreateUnicode(valueText) }; } return(WinError.S_OK); }
public static extern int StrRetToBSTR(ref STRRET pstr, IntPtr pidl, [MarshalAs(UnmanagedType.BStr)] ref string pbstr);
int IShellFolder2.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { return(((IShellFolder)this).GetDisplayNameOf(pidl, uFlags, out pName)); }
/// <summary> /// Retrieves the display name for the specified file object or subfolder. /// Return value: error code, if any /// </summary> /// <param name="pidl">Address of an ITEMIDLIST structure (PIDL) that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="uFlags">Flags used to request the type of display name to return. For a list of possible values.</param> /// <param name="pName">Address of a STRRET structure in which to return the display name.</param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> int IShellFolder.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { // Use the ShellFolderImpl to handle the details. return(((IShellFolder)shellFolderImpl).GetDisplayNameOf(pidl, uFlags, out pName)); }
static extern void StrRetToBSTR([In, Out] ref STRRET pstr, [In] IntPtr pidl, [Out, MarshalAs(UnmanagedType.BStr)] out string pbstr);
static extern void StrRetToBuf([In, Out] ref STRRET pstr, [In] IntPtr pidl, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder pszBuf, uint cchBuf);
private static extern void StrRetToBuf([In, Out] ref STRRET pstr, [In] PIDLIST pidl, [Out] StringBuilder pszBuf, [In] int cchBuf);