Embed .exe in a c++ project
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Embed .exe in a c++ project

  1. #1
    Join Date
    Mar 2009
    Posts
    7

    Embed .exe in a c++ project

    Hey,
    Is it possible to embed an extenal executable in a project?
    For example, if i want to run wget.exe, i would normally included the wget executable in the same directory as the main program, and call system("wget.exe http://domain.com/file.txt");.
    But I want my program to be minimal and only have 1 file. Instead of keeping two executable, I would like to keep everything in one file, for simplicity and less chance of messing up the program.

    How would i do this?

    Thanks.

  2. #2
    Join Date
    Jul 2002
    Posts
    2,513

  3. #3
    Join Date
    Mar 2009
    Posts
    7

    Re: Embed .exe in a c++ project

    Thanks Alex!

    I downloaded the demo and tried to build it but i didn't. I needed afxwin.h, which is MFC, which i dont have. Im using vc++ express and can't afford the professional.
    Is there a way without having to use the MFC class?

  4. #4
    Join Date
    Jul 2002
    Posts
    2,513

    Re: Embed .exe in a c++ project

    It looks like demo project is built with MFC, and BinRes class doesn't have MFC dependencies. You can use this class in non-MFC project by the same way as it is done in the demo project.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,977

    Re: Embed .exe in a c++ project

    But I want my program to be minimal and only have 1 file. Instead of keeping two executable, I would like to keep everything in one file, for simplicity and less chance of messing up the program.
    Yeah, this is what installers are about...
    Best regards,
    Igor

  6. #6
    Join Date
    Mar 2009
    Posts
    7

    Re: Embed .exe in a c++ project

    Quote Originally Posted by Alex F View Post
    It looks like demo project is built with MFC, and BinRes class doesn't have MFC dependencies. You can use this class in non-MFC project by the same way as it is done in the demo project.
    Sorry, but I'm a noob.
    I downloaded the non-demo file, and realized
    Code:
    #include "testHarness.h"
    was in the binres.cpp source file. testHarness was the demo project. The header file was not included with the non-demo file, and when i comment it out, it wouldn't compile. There were errors about undeclared identifiers.

    Could you help me create a project that simply does what binres supposed to do without anything else?


    Quote Originally Posted by Igor Vartanov
    Yeah, this is what installers are about...
    I considered that, but I'd prefer a more portable application, without the need of installation.


    On another side, I found this http://www.codeguru.com/forum/showthread.php?t=373518
    It's a cool concept, and i tried it out (BTW, im running ubuntu linux with a windows xp virtual machine).
    But it didn't work. I used the fstream to output the array onto a file. but when i compared the hex with the original file, it wasn't the same. Oh well. I'll try to solve that problem later.
    But if it does work, would there be a way to execute the array without having to actually make a file on the hard drive, but rather execute it directly from memory?

  7. #7
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Embed .exe in a c++ project

    What you are wanting to do is what DLLs were designed to do. wget is open source so you could probably make it a dll without too much work (there might even be a dll version of the project somewhere, I haven't checked). Other than that, Microsoft has already done a good deal of the hard work for you with the CInternetConnection class. Consider using that (or the WinInet API directly) to get your file from the web instead of relying on external programs.

    http://msdn.microsoft.com/en-us/library/s7seyaek.aspx

    http://msdn.microsoft.com/en-us/libr...30(VS.85).aspx

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,977

    Re: Embed .exe in a c++ project

    Quote Originally Posted by benchaz View Post
    On another side, I found this http://www.codeguru.com/forum/showthread.php?t=373518
    It's a cool concept, and i tried it out (BTW, im running ubuntu linux with a windows xp virtual machine).
    No it's not that cool. The cool one (at least in the Windows world) is to keep the binary in resources and dump it to disk whenever it's needed.

    But it didn't work. I used the fstream to output the array onto a file. but when i compared the hex with the original file, it wasn't the same. Oh well. I'll try to solve that problem later.
    But if it does work, would there be a way to execute the array without having to actually make a file on the hard drive, but rather execute it directly from memory?
    Nope, executable file is supposed to be loaded by system loader, and the latter works only with files on file system but not in-memory ones. Otherwise you are to do all the work that loader does. I doubt you ever want to.

    Well, it seems that in your case the best approach would be to just forget about wget and try to find the library with the same functionality. Or otherwise do it usual way, like others do, with installers, resources, whatever.
    Best regards,
    Igor

  9. #9
    Join Date
    Aug 2010
    Posts
    1

    Cool Re: Embed .exe in a c++ project

    Quote Originally Posted by Igor Vartanov View Post
    Yeah, this is what installers are about...
    One of the coolest tools I use are Process Explorer and Process Monitor
    http://technet.microsoft.com/en-us/s.../bb896653.aspx
    http://technet.microsoft.com/en-us/s.../bb896645.aspx
    They are cool not only for what they do, but also because they don't need installation. Every program looks like a single, standalone exe. Of course, they use the embedded resource technique for every extra file they need.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center