Esempio n. 1
0
        public static IconExtractor Open(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            if (fileName.Length == 0)
            {
                throw new ArgumentException(null, "fileName");
            }

            fileName = Path.GetFullPath(fileName);
            fileName = Environment.ExpandEnvironmentVariables(fileName);

            SafeModuleHandle moduleHandle = DllImports.LoadLibraryEx(fileName, IntPtr.Zero, LoadLibraryExFlags.LOAD_LIBRARY_AS_DATAFILE);

            if (moduleHandle.IsInvalid)
            {
                throw Win32Marshal.GetExceptionForLastWin32Error(fileName);
            }

            List <ResourceName> iconNames = new List <ResourceName>();

            DllImports.EnumResourceNames(moduleHandle, ResourceTypes.RT_GROUP_ICON, (hModule, lpszType, lpszName, lParam) =>
            {
                if (lpszType == ResourceTypes.RT_GROUP_ICON)
                {
                    iconNames.Add(new ResourceName(lpszName));
                }

                return(true);
            },
                                         IntPtr.Zero);


            return(new IconExtractor(moduleHandle, iconNames));
        }