public IconExtractor(string filename)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }

            this._hModule = NativeMethods.LoadLibrary(filename);
            if (this._hModule == IntPtr.Zero)
            {
                this._hModule = NativeMethods.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       = NativeMethods.GetModuleFileName(this._hModule, buf, buf.Capacity + 1);
            int           LastError = Marshal.GetLastWin32Error();

            if (len != 0)
            {
                this._filename = buf.ToString();
            }
            else
            {
                switch (LastError)
                {
                case ERROR_SUCCESS:
                    this._filename = filename;
                    break;

                default:
                    throw new Win32Exception();
                }
            }

            this._resInfo = new NativeMethods.IconResInfo();
            bool success = NativeMethods.EnumResourceNames(this._hModule, RT_GROUP_ICON, EnumResNameCallBack, this._resInfo);

            // bool EnumResourceNames(IntPtr hModule, int lpszType, EnumResNameProc lpEnumFunc, IconResInfo lParam);
            if (!success)
            {
                throw new Win32Exception();
            }

            this._iconCache = new Icon[this.IconCount];
        }
        private bool EnumResNameCallBack(IntPtr hModule, int lpszType, IntPtr lpszName, NativeMethods.IconResInfo lParam)
        {
            // Callback function for EnumResourceNames().

            if (lpszType == RT_GROUP_ICON)
            {
                lParam.IconNames.Add(new NativeMethods.ResourceName(lpszName));
            }

            return(true);
        }