/// <summary> /// Load the specified executable file or DLL, and get ready to extract the icons. /// </summary> /// <param name="filename">The name of a file from which icons will be extracted.</param> public IconExtractor(string filename) { if (filename == null) { throw new ArgumentNullException("filename"); } _hModule = LoadLibrary(filename); if (_hModule == IntPtr.Zero) { _hModule = LoadLibraryEx(filename, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE); if (_hModule == IntPtr.Zero) { switch (Marshal.GetLastWin32Error()) { case ERROR_FILE_NOT_FOUND: throw new FileNotFoundException("Specified file '" + filename + "' not found."); case ERROR_BAD_EXE_FORMAT: throw new ArgumentException("Specified file '" + filename + "' is not an executable file or DLL."); default: throw new Win32Exception(); } } } var buf = new StringBuilder(MAX_PATH); int len = GetModuleFileName(_hModule, buf, buf.Capacity + 1); if (len != 0) { this.Filename = buf.ToString(); } else { switch (Marshal.GetLastWin32Error()) { case ERROR_SUCCESS: this.Filename = filename; break; default: throw new Win32Exception(); } } _resInfo = new IconResInfo(); bool success = EnumResourceNames(_hModule, RT_GROUP_ICON, this.EnumResNameCallBack, _resInfo); if (!success) { throw new Win32Exception(); } _iconCache = new Icon[this.IconCount]; }
/// <summary> /// Load the specified executable file or DLL, and get ready to extract the icons. /// </summary> /// <param name="filename">The name of a file from which icons will be extracted.</param> public IconExtractor(string filename) { if (filename == null) { throw new ArgumentNullException("filename"); } this._hModule = LoadLibrary(filename); if (this._hModule == IntPtr.Zero) { this._hModule = LoadLibraryEx(filename, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE); if (this._hModule == IntPtr.Zero) { switch (Marshal.GetLastWin32Error()) { case ERROR_FILE_NOT_FOUND: throw new FileNotFoundException("Specified file '" + filename + "' not found."); case ERROR_BAD_EXE_FORMAT: throw new ArgumentException("Specified file '" + filename + "' is not an executable file or DLL."); default: throw new Win32Exception(); } } } this._resInfo = new IconResInfo(); bool success = EnumResourceNames(this._hModule, RT_GROUP_ICON, EnumResNameCallBack, this._resInfo); if (!success) { throw new Win32Exception(); } this._iconCache = new Icon[this.IconCount]; }
private static extern bool EnumResourceNames( IntPtr hModule, int lpszType, EnumResNameProc lpEnumFunc, IconResInfo lParam);
private bool EnumResNameCallBack(IntPtr hModule, int lpszType, IntPtr lpszName, IconResInfo lParam) { // Callback function for EnumResourceNames(). if (lpszType == RT_GROUP_ICON) { lParam.IconNames.Add(new ResourceName(lpszName)); } return(true); }
/// <summary> /// Load the specified executable file or DLL, and get ready to extract the icons. /// </summary> /// <param name="filename">The name of a file from which icons will be extracted.</param> public IconExtractor(string filename) { if (filename == null) { throw new ArgumentNullException("filename"); } this._hModule = LoadLibrary(filename); if (this._hModule == IntPtr.Zero) { this._hModule = LoadLibraryEx(filename, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE); if (this._hModule == IntPtr.Zero) { switch (Marshal.GetLastWin32Error()) { case ERROR_FILE_NOT_FOUND: throw new FileNotFoundException("Specified file '" + filename + "' not found."); case ERROR_BAD_EXE_FORMAT: throw new ArgumentException("Specified file '" + filename + "' is not an executable file or DLL."); default: throw new Win32Exception(); } } } StringBuilder buf = new StringBuilder(MAX_PATH); int len = GetModuleFileName(this._hModule, buf, buf.Capacity + 1); if (len != 0) { this._filename = buf.ToString(); } else { switch (Marshal.GetLastWin32Error()) { case ERROR_SUCCESS: this._filename = filename; break; default: throw new Win32Exception(); } } this._resInfo = new IconResInfo(); bool success = EnumResourceNames(this._hModule, RT_GROUP_ICON, EnumResNameCallBack, this._resInfo); if (!success) { throw new Win32Exception(); } this._iconCache = new Icon[this.IconCount]; }
private bool EnumResNameCallBack(IntPtr hModule, int lpszType, IntPtr lpszName, IconResInfo lParam) { // Callback function for EnumResourceNames(). if (lpszType == RT_GROUP_ICON) { lParam.IconNames.Add(new ResourceName(lpszName)); } return true; }