Example #1
0
        /// <summary>
        /// Create a resource of a given type.
        /// </summary>
        /// <param name="hModule">Module handle.</param>
        /// <param name="hResourceGlobal">Pointer to the resource in memory.</param>
        /// <param name="type">Resource type.</param>
        /// <param name="name">Resource name.</param>
        /// <param name="wIDLanguage">Language ID.</param>
        /// <param name="size">Size of resource.</param>
        /// <returns>A specialized or a generic resource.</returns>
        protected Resource CreateResource(
            IntPtr hModule,
            IntPtr hResourceGlobal,
            ResourceId type,
            ResourceId name,
            UInt16 wIDLanguage,
            int size)
        {
            if (type.IsIntResource())
            {
                switch (type.ResourceType)
                {
                case Kernel32.ResourceTypes.RT_VERSION:
                    return(new VersionResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_GROUP_CURSOR:
                    return(new CursorDirectoryResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_GROUP_ICON:
                    return(new IconDirectoryResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_MANIFEST:
                    return(new ManifestResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_BITMAP:
                    return(new BitmapResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_MENU:
                    return(new MenuResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_DIALOG:
                    return(new DialogResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_STRING:
                    return(new StringResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_FONTDIR:
                    return(new FontDirectoryResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_FONT:
                    return(new FontResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));

                case Kernel32.ResourceTypes.RT_ACCELERATOR:
                    return(new AcceleratorResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));
                }
            }

            return(new GenericResource(hModule, hResourceGlobal, type, name, wIDLanguage, size));
        }
 internal static void WriteResourceId(BinaryWriter w, ResourceId rc)
 {
     if (rc == null)
     {
         w.Write((UInt16)0);
     }
     else if (rc.IsIntResource())
     {
         w.Write((UInt16)0xFFFF);
         w.Write((UInt16)rc.Id);
     }
     else
     {
         ResourceUtil.PadToWORD(w);
         w.Write(Encoding.Unicode.GetBytes(rc.Name));
         w.Write((UInt16)0);
     }
 }