// // Copyright (c) PlaceholderCompany. All rights reserved. // namespace SystemTrayMenu.DllImports { using System; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; /// /// wraps the methodcalls to native windows dll's. /// public static partial class NativeMethods { [SupportedOSPlatform("windows")] [DllImport("Shell32.dll", EntryPoint = "SHGetFileInfo", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] internal static extern IntPtr Shell32SHGetFileInfo( string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags); // Retrieves the IShellFolder interface for the desktop folder, which is the root of the Shell's namespace. [SupportedOSPlatform("windows")] [DllImport("shell32.dll", EntryPoint = "SHGetDesktopFolder", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] internal static extern int Shell32SHGetDesktopFolder(out IntPtr ppshf); [SupportedOSPlatform("windows")] [DllImport("shlwapi.dll", EntryPoint = "StrCmpLogicalW", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] internal static extern int ShlwapiStrCmpLogicalW(string x, string y); // Takes a STRRET structure returned by IShellFolder::GetDisplayNameOf, converts it to a string, and places the result in a buffer. [SupportedOSPlatform("windows")] [DllImport("shlwapi.dll", EntryPoint = "StrRetToBuf", ExactSpelling = false, SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] [DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)] internal static extern int ShlwapiStrRetToBuf(IntPtr pstr, IntPtr pidl, StringBuilder pszBuf, int cchBuf); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] internal struct SHFILEINFO { public IntPtr hIcon; public int iIcon; public uint dwAttributes; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] public string szDisplayName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NAMESIZE)] public string szTypeName; private const int NAMESIZE = 80; private const int MAX_PATH = 256; } } }