Win32.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Runtime.InteropServices.ComTypes;
  4. namespace IMAPI2.MediaItem
  5. {
  6. [StructLayout(LayoutKind.Sequential)]
  7. public struct SHFILEINFO
  8. {
  9. public IntPtr hIcon;
  10. public IntPtr iIcon;
  11. public uint dwAttributes;
  12. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
  13. public string szDisplayName;
  14. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
  15. public string szTypeName;
  16. };
  17. class Win32
  18. {
  19. public const uint SHGFI_ICON = 0x100;
  20. public const uint SHGFI_LARGEICON = 0x0; // Large icon
  21. public const uint SHGFI_SMALLICON = 0x1; // Small icon
  22. [DllImport("shell32.dll")]
  23. public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
  24. [DllImport("user32.dll")]
  25. public static extern bool DestroyIcon(IntPtr handle);
  26. public const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
  27. public const uint STGM_DELETEONRELEASE = 0x04000000;
  28. public const uint STGM_SHARE_DENY_WRITE = 0x00000020;
  29. public const uint STGM_SHARE_DENY_NONE = 0x00000040;
  30. public const uint STGM_READ = 0x00000000;
  31. [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false, EntryPoint = "SHCreateStreamOnFileW")]
  32. public static extern void SHCreateStreamOnFile(string fileName, uint mode, ref IStream stream);
  33. }
  34. }