Пример #1
0
        /// <summary>
        /// Read an icon resource from a previously loaded module.
        /// </summary>
        /// <param name="hModule">Module handle.</param>
        /// <param name="lpRes">Pointer to a directory entry in the hardware-independent icon resource.</param>
        /// <returns>Pointer to the end of the icon resource.</returns>
        internal override IntPtr Read(IntPtr hModule, IntPtr lpRes)
        {
            _header = (Kernel32.GRPICONDIRENTRY)Marshal.PtrToStructure(
                lpRes, typeof(Kernel32.GRPICONDIRENTRY));

            IntPtr hIconInfo = Kernel32.FindResourceEx(
                hModule, _type.Id, (IntPtr)_header.nID, _language);

            if (hIconInfo == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            IntPtr hIconRes = Kernel32.LoadResource(hModule, hIconInfo);

            if (hIconRes == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            IntPtr dibBits = Kernel32.LockResource(hIconRes);

            if (dibBits == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            ReadImage(dibBits, (UInt32)Kernel32.SizeofResource(hModule, hIconInfo));

            return(new IntPtr(lpRes.ToInt32() + Marshal.SizeOf(_header)));
        }
Пример #2
0
        /// <summary>
        /// Read an icon resource from a previously loaded module.
        /// </summary>
        /// <param name="hModule">Module handle.</param>
        /// <param name="lpRes">Pointer to a directory entry in the hardware-independent icon resource.</param>
        /// <returns>Pointer to the end of the icon resource.</returns>
        internal override IntPtr Read(IntPtr hModule, IntPtr lpRes)
        {
            _header = (Kernel32.GRPICONDIRENTRY)Marshal.PtrToStructure(
                lpRes, typeof(Kernel32.GRPICONDIRENTRY));

            IntPtr hIconInfo = Kernel32.FindResourceEx(
                hModule, _type.Id, (IntPtr) _header.nID, _language);

            if (hIconInfo == IntPtr.Zero)
                throw new Win32Exception(Marshal.GetLastWin32Error());

            IntPtr hIconRes = Kernel32.LoadResource(hModule, hIconInfo);
            if (hIconRes == IntPtr.Zero)
                throw new Win32Exception(Marshal.GetLastWin32Error());

            IntPtr dibBits = Kernel32.LockResource(hIconRes);
            if (dibBits == IntPtr.Zero)
                throw new Win32Exception(Marshal.GetLastWin32Error());

            ReadImage(dibBits, (UInt32) Kernel32.SizeofResource(hModule, hIconInfo));

            return new IntPtr(lpRes.ToInt32() + Marshal.SizeOf(_header));
        }