/// <summary>
        ///   A structured resource embedded in an executable module.
        /// </summary>
        /// <param name = "hModule">Module handle.</param>
        /// <param name = "hResource">Resource handle.</param>
        /// <param name = "type">Resource type.</param>
        /// <param name = "name">Resource name.</param>
        /// <param name = "language">Language ID.</param>
        /// <param name = "size">Resource size.</param>
        internal Resource(IntPtr hModule, IntPtr hResource, ResourceId type, ResourceId name, UInt16 language, int size) {
            _hModule = hModule;
            _type = type;
            _name = name;
            _language = language;
            _hResource = hResource;
            _size = size;

            LockAndReadResource(hModule, hResource);
        }
Пример #2
0
 /// <summary>
 ///   An existing string resource.
 /// </summary>
 /// <param name = "hModule">Module handle.</param>
 /// <param name = "hResource">Resource ID.</param>
 /// <param name = "type">Resource type.</param>
 /// <param name = "name">Resource name.</param>
 /// <param name = "language">Language ID.</param>
 /// <param name = "size">Resource size.</param>
 public StringResource(IntPtr hModule, IntPtr hResource, ResourceId type, ResourceId name, UInt16 language, int size)
     : base(hModule, hResource, type, name, language, size)
 {
 }
Пример #3
0
 /// <summary>
 ///   A new string resource of a given block id.
 /// </summary>
 /// <param name = "blockId">Block id.</param>
 public StringResource(ResourceId blockId)
     : base(IntPtr.Zero, IntPtr.Zero, new ResourceId(ResourceTypes.RT_STRING), blockId, ResourceUtil.NEUTRALLANGID, 0)
 {
 }
Пример #4
0
 /// <summary>
 ///   Save a resource to an executable (.exe or .dll) file.
 /// </summary>
 /// <param name = "filename">Path to an executable file.</param>
 /// <param name = "name">Resource name.</param>
 /// <param name = "type">Resource type.</param>
 /// <param name = "langid">Language id.</param>
 internal void SaveTo(string filename, ResourceId type, ResourceId name, UInt16 langid)
 {
     var data = WriteAndGetBytes();
     SaveTo(filename, type, name, langid, data);
 }
Пример #5
0
        /// <summary>
        ///   Load a resource from an executable (.exe or .dll) module.
        /// </summary>
        /// <param name = "hModule">An executable (.exe or .dll) module.</param>
        /// <param name = "type">Resource type.</param>
        /// <param name = "name">Resource name.</param>
        /// <param name = "lang">Resource language.</param>
        internal void LoadFrom(IntPtr hModule, ResourceId type, ResourceId name, UInt16 lang)
        {
            if (IntPtr.Zero == hModule) {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            var hRes = Kernel32.FindResourceEx(hModule, type.Id, name.Id, lang);
            if (IntPtr.Zero == hRes) {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            var hGlobal = Kernel32.LoadResource(hModule, hRes);
            if (IntPtr.Zero == hGlobal) {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            var lpRes = Kernel32.LockResource(hGlobal);

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

            _size = Kernel32.SizeofResource(hModule, hRes);
            if (_size <= 0) {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            _type = type;
            _name = name;
            _language = lang;

            Read(hModule, lpRes);
        }
Пример #6
0
        /// <summary>
        ///   Load a resource from an executable (.exe or .dll) file.
        /// </summary>
        /// <param name = "filename">An executable (.exe or .dll) file.</param>
        /// <param name = "name">Resource name.</param>
        /// <param name = "type">Resource type.</param>
        /// <param name = "lang">Resource language.</param>
        internal void LoadFrom(string filename, ResourceId type, ResourceId name, UInt16 lang)
        {
            var hModule = IntPtr.Zero;

            try {
                hModule = Kernel32.LoadLibraryEx(filename, IntPtr.Zero, Kernel32Contants.DONT_RESOLVE_DLL_REFERENCES | Kernel32Contants.LOAD_LIBRARY_AS_DATAFILE);

                LoadFrom(hModule, type, name, lang);
            }
            finally {
                if (hModule != IntPtr.Zero) {
                    Kernel32.FreeLibrary(hModule);
                }
            }
        }
Пример #7
0
        /// <summary>
        ///   Save a resource to an executable (.exe or .dll) file.
        /// </summary>
        /// <param name = "filename">Path to an executable file.</param>
        /// <param name = "name">Resource name.</param>
        /// <param name = "type">Resource type.</param>
        /// <param name = "lang">Resource language.</param>
        /// <param name = "data">Resource data.</param>
        internal static void SaveTo(string filename, ResourceId type, ResourceId name, UInt16 lang, byte[] data)
        {
            var h = Kernel32.BeginUpdateResource(filename, false);

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

            if (!Kernel32.UpdateResource(h, type.Id, name.Id, lang, data, (data == null ? 0 : (uint) data.Length))) {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            if (!Kernel32.EndUpdateResource(h, false)) {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Пример #8
0
 /// <summary>
 ///   Delete a resource from an executable (.exe or .dll) file.
 /// </summary>
 /// <param name = "filename">Path to an executable file.</param>
 /// <param name = "name">Resource name.</param>
 /// <param name = "type">Resource type.</param>
 /// <param name = "lang">Resource language.</param>
 public static void Delete(string filename, ResourceId type, ResourceId name, UInt16 lang)
 {
     SaveTo(filename, type, name, lang, null);
 }
Пример #9
0
 /// <summary>
 ///   An existing icon resource.
 /// </summary>
 /// <param name = "hModule">Module handle.</param>
 /// <param name = "hResource">Resource ID.</param>
 /// <param name = "type">Resource type.</param>
 /// <param name = "name">Resource name.</param>
 /// <param name = "language">Language ID.</param>
 /// <param name = "size">Resource size.</param>
 internal IconResource(IntPtr hModule, IntPtr hResource, ResourceId type, ResourceId name, UInt16 language, int size)
     : base(hModule, hResource, type, name, language, size)
 {
 }
Пример #10
0
 /// <summary>
 ///   Convert into an icon resource that can be written into an executable.
 /// </summary>
 /// <param name = "icon">Icon image.</param>
 /// <param name = "id">Icon Id.</param>
 /// <param name = "language">Resource language.</param>
 /// <returns>An icon resource.</returns>
 public IconResource(IconFileIcon icon, ResourceId id, UInt16 language)
     : base(icon, new ResourceId(ResourceTypes.RT_ICON), id, language)
 {
 }
Пример #11
0
 /// <summary>
 ///   An existing font resource.
 /// </summary>
 /// <param name = "hModule">Module handle.</param>
 /// <param name = "hResource">Resource ID.</param>
 /// <param name = "type">Resource type.</param>
 /// <param name = "name">Resource name.</param>
 /// <param name = "language">Language ID.</param>
 /// <param name = "size">Resource size.</param>
 public FontDirectoryResource(IntPtr hModule, IntPtr hResource, ResourceId type, ResourceId name, UInt16 language, int size)
     : base(hModule, hResource, type, name, language, size)
 {
 }