Skip to content

Documentation

Koray Üstündağ edited this page May 16, 2023 · 2 revisions

ShellIconExtractor Class

The ShellIconExtractor class provides a convenient way to extract icons from the Shell32.dll file.

Constructor

ShellIconExtractor(string filePath, int iconIndex)

Creates a new instance of the ShellIconExtractor class with the specified file path and icon index.

  • filePath: The path of the file from which to extract the icon.
  • iconIndex: The index of the icon to extract from the file.

Methods

GetIcon(int size) : Icon

Gets the extracted icon with the specified size.

  • size: The size of the icon to retrieve.

Usage Example

// Create a new instance of ShellIconExtractor
var iconExtractor = new ShellIconExtractor("C:\\path\\to\\file.txt", 0);

try
{
    // Get the icon with size 32x32
    var icon = iconExtractor.GetIcon(32);

    // Use the icon as needed
    // ...
}
catch (Exception ex)
{
    Console.WriteLine("An error occurred: " + ex.Message);
}
finally
{
    // Dispose of the ShellIconExtractor instance
    iconExtractor.Dispose();
}

Exceptions

The ShellIconExtractor class can throw the following exceptions:

  • ArgumentException: Thrown if the arguments provided to the constructor are invalid.
  • InvalidOperationException: Thrown if the icon handle is invalid.
  • OutOfMemoryException: Thrown if there is not enough memory to create the icon.
  • Win32Exception: Thrown if an error occurs in the Win32 API calls.
  • ExternalException: Thrown if an external exception occurs.
  • NotSupportedException: Thrown if the operation is not supported.
  • Exception: Thrown for any other unhandled exception.

For more information, refer to the API Reference documentation.

Clone this wiki locally