How to generate another program from a program

Source: Internet
Author: User

Not long ago, everyone was talking about how to generate another program from a program, I proposed that another program be compiled together with a resource file in a program, and then regenerated as needed when the program was run, and here is an example of me where I'm going to bring the WordPad ( Writer.exe) when resources.

Below is the source code

The resource file has a writer.exe length of 204800, defined as a "custom" resource in the resource file, 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'll read the resource and write it to a 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);
}

When the resource is added and generated, I can't do it with Borland ResourceWorkShop4.5, and finally the res file generated with the VB6 resource editor.

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.