Generate another program from one program (Resource Method)

Source: Internet
Author: User

File title: fromProgramGenerate another program (Resource Method) by: Alias Name

Not long ago, everyone was discussing how to use one program to generate another program. I proposed to compile another program when the resource file is included in the program, and then generate it again as needed during the program running, the following is an example of mine. Here, I use Windows-based tablet (writer.exe) as a resource.

Below isSource code

// The writer.exe length of the resource file is 204800. It is defined as "Custom" resource in the resource file and is numbered 1111.

hrsrc hmyres; // resource handle
hglobal hgpt; // resource pointer
lpvoid lpbuff; // resource buffer pointer
DWORD rcsize = 204800; // resource size
handle hfile; // file to write
lpdword dwbyte; // byte size had been write
dwbyte = & rcsize; // locate the resource and load the resource to memory and lock it
hmyres = findresource (hmodule) getwindowlong (handle, gwl_hinstance), makeintre source (1111 ), "Custom");
If (hmyres = NULL)
showmessage (syserrormessage (getlasterror ();
hgpt = loadresource (null, hmyres );
If (hgpt = NULL)
showmessage (syserrormessage (getlasterror ();
lpbuff = lockresource (hgpt);

// Now I will read the resource and write it to an file

Try
{
Hfile = createfile ("E: \ mywriter.exe", generic_write, 0, null, create_always, file_attribute_normal, null );
Writefile (hfile, lpbuff, rcsize, dwbyte, null );
If (* dwbyte! = 204800)
Showmessage ("failed to write to file ");
}
_ Finally
{
Closehandle (hfile );
}

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.