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 );
}