コード例 #1
0
        public static void GetFolderInfo(string fullPath, out string DisplayName, out string TypeName)
        {
            IntPtr pidRoot = IntPtr.Zero;

            Win32Shell.SHFILEINFO shInfo = new Win32Shell.SHFILEINFO();

            SHGetFileInfo(fullPath, 0, ref shInfo, (uint)Marshal.SizeOf(shInfo), SHGFI_DISPLAYNAME | SHGFI_TYPENAME);
            DisplayName = shInfo.szDisplayName;
            TypeName    = shInfo.szTypeName;
            if (pidRoot != IntPtr.Zero)
            {
                Win32Shell.IMalloc malloc;
                Win32Shell.SHGetMalloc(out malloc);
                malloc.Free(pidRoot);
            }
        }
コード例 #2
0
        public static void GetFolderInfo(Guid guid, out string DisplayName, out string FullPath)
        {
            IntPtr pidRoot = IntPtr.Zero;
            IntPtr pPath   = IntPtr.Zero;

            Win32Shell.SHFILEINFO shInfo = new Win32Shell.SHFILEINFO();

            Win32Shell.SHGetKnownFolderIDList(guid, 0, IntPtr.Zero, out pidRoot);
            Win32Shell.SHGetFileInfo(pidRoot, 0, ref shInfo, (uint)Marshal.SizeOf(shInfo), SHGFI_DISPLAYNAME | SHGFI_TYPENAME | SHGFI_PIDL);

            DisplayName = shInfo.szDisplayName;
            if (pidRoot != IntPtr.Zero)
            {
                Win32Shell.IMalloc malloc;
                Win32Shell.SHGetMalloc(out malloc);
                malloc.Free(pidRoot);
            }
            SHGetKnownFolderPath(guid, 0, IntPtr.Zero, out pPath);
            FullPath = Marshal.PtrToStringUni(pPath);
            Marshal.FreeCoTaskMem(pPath);
        }