Introduction
You can execute another program from your application without the need to attach the execution file with your program. The exe file will be stored in the application resources as a bitmap image, and in the runtime mode this image will be written in an exe file.
Once the exe file has been created, there is no problem to run it.
These steps will explain for you how to do that:
- From your resource view, insert new resource type, let's call it "EXE".
- From the "EXE" type, import the execution file you want to include in it.
Until now, you have loaded the Execution file in your resources, and you need write it in an execution file to be ready for running. Create new function in your program, let's call it Run()
, like this:
bool Run()
{
CFile f;
char* pFileName = "Execution.exe";
if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite, NULL ) )
{
AfxMessageBox("Can not create file!");
return 0;
}
CString path = f.GetFilePath();
HGLOBAL hRes;
HRSRC hResInfo;
HINSTANCE insApp = AfxGetInstanceHandle();
hResInfo = FindResource(insApp,(LPCSTR)IDR_EXE4,"EXE");
hRes = LoadResource(insApp,hResInfo );
DWORD dFileLength = SizeofResource( insApp, hResInfo );
f.WriteHuge((LPSTR)hRes,dFileLength);
f.Close();
HINSTANCE HINSsd = ShellExecute(NULL, "open",path, NULL, NULL,
SW_SHOWNORMAL);
return 1;
}
That's all.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.