/// <summary> /// Create a new instance of the <see cref="ShellObject" /> class. /// </summary> /// <param name="pidl"><c>PIDL</c>。</param> /// <param name="riid"><c>GUID</c>。</param> /// <returns></returns> private static ShellObject CreateShellObject(IntPtr pidl, ref Guid riid) { IShellItem2 shellItem2; var code = ShellNativeMethods.SHCreateItemFromIDList(pidl, ref riid, out shellItem2); if (HRESULT.Failed(code)) { return(null); } return(ShellFactory.FromShellItem(new ShellItem(shellItem2))); }
/// <summary> /// Create new instance of the <see cref="ShellItem" /> class /// to the specified <c>PIDL</c>. /// </summary> /// <param name="pidl"><c>PIDL</c>.</param> /// <returns><see cref="ShellItem" />.</returns> /// <exception cref="ArgumentException"><paramref name="pidl" /> is <c>null</c>.</exception> /// <exception cref="ShellException">Failed to create <see cref="ShellItem" />.</exception> internal static ShellItem FromPIDL(PIDL pidl) { Contract.Requires <ArgumentException>(pidl != PIDL.Null); Contract.Ensures(Contract.Result <ShellItem>() != null); IShellItem2 shellItem; var code = ShellNativeMethods.SHCreateItemFromIDList( pidl, ref ShellIIDGuid.IShellItem2, out shellItem); if (HRESULT.Failed(code)) { throw new ShellException(ErrorMessages.ShellFactoryUnableToCreateItem, Marshal.GetExceptionForHR(code)); } return(new ShellItem(shellItem)); }