File size: 1,540 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#nullable enable
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
internal static partial class Interop
{
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Keep native struct names.")]
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter", Justification = "Keep native struct names.")]
internal static partial class Windows
{
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct SHFILEINFO
{
internal nint hIcon;
internal int iIcon;
internal uint dwAttributes;
internal fixed char szDisplayName[260];
internal fixed char szTypeName[80];
public static readonly uint s_Size = (uint)sizeof(SHFILEINFO);
}
[LibraryImport("shell32.dll", EntryPoint = "SHGetFileInfoW", StringMarshalling = StringMarshalling.Utf16)]
internal static partial nint SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
internal static int SHGetFileInfo(string pszPath)
{
// flag used to ask to return exe type
const uint SHGFI_EXETYPE = 0x000002000;
var shinfo = new SHFILEINFO();
return (int)SHGetFileInfo(pszPath, 0, ref shinfo, SHFILEINFO.s_Size, SHGFI_EXETYPE);
}
}
}
|