Click here to Skip to main content
Licence 
First Posted 23 Mar 2001
Views 38,374
Bookmarked 28 times

Launching Program from Resources.

By | 27 Mar 2001 | Article
A new way to execute programs from resources.

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:

  1. From your resource view, insert new resource type, let's call it "EXE".
  2. 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; //This is the file which will be used  as an exe file  
    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;
        //Get the instance handle for this app   
    HINSTANCE insApp = AfxGetInstanceHandle();
        //find the handle for the EXE resource    file
    hResInfo = FindResource(insApp,(LPCSTR)IDR_EXE4,"EXE");
    hRes = LoadResource(insApp,hResInfo );   // Load it

 
        //Calculate the size of the exe file 
    DWORD dFileLength = SizeofResource( insApp, hResInfo );  
    f.WriteHuge((LPSTR)hRes,dFileLength);  //write it 
    f.Close();
    HINSTANCE HINSsd = ShellExecute(NULL, "open",path, NULL, NULL, 
                                        SW_SHOWNORMAL); //Execute it.  
    return 1;
 
   }

That's all.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Mohammad Salah



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralHmmm... PinmemberTomas Brennan15:39 18 Feb '10  
Questionhow can in insert my exe file in a bitmap Pinmembersepel0:09 16 Feb '07  
GeneralTemporary PinmemberNnuller22:43 24 Mar '04  
GeneralBad idea PinmemberAndreas Saurwein6:12 13 Feb '03  
QuestionPut into temp directory? PinmemberHarold Bamford13:06 1 Nov '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 28 Mar 2001
Article Copyright 2001 by Mohammad Salah
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid