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.