Updateresource (add, delete, or replace resources in an executable file)

Source: Internet
Author: User


Function: adds, deletes, or replaces resources in an executable file.

Function prototype: [Code] updateresource hupdate, lptype, lpname, wlanguage, lpdata, cbdata [/Code] parameter description: [Code] hupdate-> handle for updating resources created by the beginupdateresource Function
Lptype-> points to the string indicating the resource type to be updated. It uses null as the Terminator. For details about the type, see the remarks section.
Lpname-> point to the string indicating the name of the resource to be updated. It uses null as the Terminator.
Wlanguage-> specifies the language ID of the resource to be updated.
Lpdata-> pointer to the resource data of the executable file to be inserted. If the resource is one of the predefined type values, the data must be effectively and appropriately arranged. Note that this is the raw binary data stored in the executable file, rather than the data provided by loadlcon, loadstring, or other loading special resource functions. All data containing strings and texts must be in unicode format. ipdata cannot point to ANSI data.
If it is null, the specified resource will be deleted from the executable file.
Cbdata-> specify the data size of resource data in lpdata. the return value is [/Code] in bytes. [Code] is successful, and the return value is non-zero. If the return value is failed, the return value is zero. To obtain more error information, call the getlasterror function. [/Code] ********************************** *
Note:
1. Database: Kernel32
2. The application repeatedly uses updateresource to change resource data. Each updateresource call takes up a list of additions, deletions, and replacements in the system, but does not actually write data to an executable file. The application must write each accumulated change to the executable file by using the endupdateresource function.
3. Type table: [Code] rt_accelerator-> accelerator table
Rt_anicursor-> Dynamic Cursor
Rt_aniicon-> dynamic icon
Rt_bitmap-> bitmap Resources
Rt_cursor-> hardware-supported cursor Resources
Di_dialog-> dialog box
Rt_font-> font Resources
Rt_fontdir-> font directory Resource
Rt_group_cursor-> hardware-independent cursor Resource
Rt_group_icon-> target resources unrelated to hardware
Rt_html-> HTML document
Rt_icon-> hardware-supported ICON resources
Rt_menu-> menu resource
Rt_messagetable-> message table entry
Rt_plugplay-> plug-and-play Resources
Rt_rcdata-> application-defined resources (raw data or custom resources)
Rt_string-> orders table entry
Rt_version-> Version Resource
Rt_vxd-> VxD [/Code]

Bool replaceico (maid) <br/>{< br/> handle hico; <br/> // open the icon file on the hard disk <br/> If (! (Hico =: createfile (lpszico, generic_read, file_share_read, null, open_existing, file_attribute_normal, null) <br/>{< br/> return false; <br/>}< br/> long loffset; // the offset of the resource in the file <br/> DWORD dwsize; // the size of the loaded resource <br/> DWORD dwreadbyte; // the actual size of the file to be read, which is mandatory by the API. Actually, it's useless ...... <Br/> lpvoid lpres; // point to the resource for updating rt_icon <br/> lpvoid lpgico; // point to the resource for updating rt_group_icon <br/> const byte bygsize = 0x18; // The resource size of rt_group_icon, which is a constant. <Br/> // allocate the memory of the rt_group_icon resource. <Br/> If (! (Lpgico = new byte [bygsize]) {: closehandle (hico); Return false ;}< br/> memset (lpgico, 0, bygsize ); // reset the rt_group_icon resource memory <br/>: readfile (hico, lpgico, 0x06, & dwreadbyte, null ); // read the rt_group_icon resource header from the file <br/>: readfile (hico, (lpvoid) (byte *) lpgico + 0x08), 0x0c, & dwreadbyte, null); // read the rt_group_icon resource from the file <br/> // obtain the ICO resource size. <Br/> memcpy (void *) & dwsize, (void *) (byte *) lpgico + 0x10), sizeof (DWORD )); <br/> // gets the offset of the ICO resource. <Br/>: readfile (hico, (void *) & loffset, sizeof (long), & dwreadbyte, null); <br/> // allocate the ICO resource memory. <Br/> If (! (Lpres = new byte [dwsize]) {Delete [] lpgico;: closehandle (hico); Return false ;} <br/> // offset file pointer <br/>: setfilepointer (hico, loffset, null, file_begin); <br/> // read the icon resource to the memory. <Br/>: readfile (hico, lpres, dwsize, & dwreadbyte, null); <br/>: closehandle (hico ); <br/> // open the executable file of the icon to be changed. <Br/> handle Happ; <br/> If (null = (HAPP =: beginupdateresource (lpszapp, null ))) <br/>{< br/> Delete [] lpgico; <br/> Delete [] lpres; <br/> return false; <br/>}< br/> // tag resource update <br/>: updateresource (HAPP, rt_group_icon, makeintresource (1), 0, lpgico, bygsize ); <br/>: updateresource (HAPP, rt_icon, makeintresource (1), 0, lpres, dwsize ); <br/> // write a new resource <br/> int error = 0; <br/> If (!: Endupdateresource (HAPP, false) <br/>{< br/> Delete [] lpgico; <br/> Delete [] lpres; <br/> error = getlasterror (); <br/> return false; <br/>}< br/> Delete [] lpgico; <br/> Delete [] lpres; <br/> return true; <br/>}< br/> 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.