private void loadFromLibrary(string libraryFile, string resourceName) { string message = ""; bool flag = false; IntPtr zero = IntPtr.Zero; IntPtr hResInfo = IntPtr.Zero; IntPtr hInstance = IntPtr.Zero; IntPtr lPtr = IntPtr.Zero; try { hInstance = LoadLibraryEx(libraryFile, IntPtr.Zero, 2); if (hInstance != IntPtr.Zero) { hResInfo = FindResource(hInstance, resourceName, (IntPtr)14); if (hResInfo != IntPtr.Zero) { zero = LoadResource(hInstance, hResInfo); if (zero != IntPtr.Zero) { lPtr = LockResource(zero); if (lPtr != IntPtr.Zero) { int num = this.readResourceIconFileHeader(lPtr); MEMICONDIRENTRY[] memicondirentryArray = new MEMICONDIRENTRY[num]; int ofs = 6; for (int i = 0; i < num; i++) { memicondirentryArray[i] = new MEMICONDIRENTRY(lPtr, ofs); ofs += 14; } FreeResource(zero); zero = IntPtr.Zero; IcDvImg[] icons = new IcDvImg[num]; for (int j = 0; j < num; j++) { string lpName = string.Format("#{0:N0}", memicondirentryArray[j].nID); hResInfo = FindResource(hInstance, lpName, (IntPtr)3); if (hResInfo == IntPtr.Zero) { message = string.Format("Could not find the component icon resource with id {0}", memicondirentryArray[j].nID); flag = true; break; } zero = LoadResource(hInstance, hResInfo); if (zero == IntPtr.Zero) { message = string.Format("Could not load the component icon resource with id {0}", memicondirentryArray[j].nID); flag = true; break; } int length = SizeofResource(hInstance, hResInfo); if ((length > 0) && (length == memicondirentryArray[j].dwBytesInRes)) { lPtr = LockResource(zero); byte[] destination = new byte[length]; Marshal.Copy(lPtr, destination, 0, length); icons[j] = new IcDvImg(destination); } else { message = string.Format("Component icon resource with id {0} is corrupt", memicondirentryArray[j].nID); flag = true; } } if (!flag) { this.iconCollection = new IconDeviceImageCollection(icons); } } else { message = "Can't lock resource for reading."; flag = true; } } else { message = "Can't load resource for reading."; flag = true; } } else { message = "Can't find resource."; flag = true; } } else { message = "Can't load library."; flag = true; } } catch (Exception exception) { flag = true; message = exception.Message; } finally { if (zero != IntPtr.Zero) { FreeResource(zero); } if (hInstance != IntPtr.Zero) { FreeLibrary(hInstance); } if (flag) { throw new IconExException(message); } } }
private void loadInitialise() { this.iconFile = ""; this.resourceId = -1; this.libraryFile = ""; this.iconCollection = new IconDeviceImageCollection(); }
private void loadFromFile(string iconFile) { this.loadInitialise(); FileStream input = new FileStream(iconFile, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader br = new BinaryReader(input); try { int num = this.readIconFileHeader(br); ICONDIRENTRY[] icondirentryArray = new ICONDIRENTRY[num]; for (int i = 0; i < num; i++) { icondirentryArray[i] = new ICONDIRENTRY(br); } IcDvImg[] icons = new IcDvImg[num]; for (int j = 0; j < num; j++) { input.Seek((long)icondirentryArray[j].dwImageOffset, SeekOrigin.Begin); byte[] buffer = new byte[icondirentryArray[j].dwBytesInRes]; br.Read(buffer, 0, icondirentryArray[j].dwBytesInRes); icons[j] = new IcDvImg(buffer); } this.iconCollection = new IconDeviceImageCollection(icons); } catch (Exception exception) { if (exception is SystemException) { throw exception; } throw new IconExException("Failed to read icon file.", exception); } finally { br.Close(); } this.iconFile = iconFile; }
public void Dispose() { if (this.iconCollection != null) { this.iconCollection.Dispose(); this.iconCollection = null; } }
public IconMethod1(string libraryFile, string resourceName) { this.iconCollection = null; this.iconFile = null; this.libraryFile = null; this.resourceId = -1; this.resourceName = null; this.FromLibrary(libraryFile, resourceName); }
public IconMethod1(string iconFile) { this.iconCollection = null; this.iconFile = null; this.libraryFile = null; this.resourceId = -1; this.resourceName = null; this.loadFromFile(iconFile); }
// Methods public IconMethod1() { this.iconCollection = null; this.iconFile = null; this.libraryFile = null; this.resourceId = -1; this.resourceName = null; }