linking 2 .exe files

I have imported a resource which is a very small .exe. Now I would like to execute this resource (program) from within within my VC++ program. Kind of like playing a wav file, except it's an exe file. Can anyone tell me how to do this or maybe point me in the right direction?
I'm trying to write a program that can combine an outside programe to my program by the time of compiling. That would give me only one file to distribute instead of making sure the user has both.
Thanks
[499 byte] By [lordpac] at [2007-11-16 10:24:07]
# 1 Re: linking 2 .exe files
I have imported a resource which is a very small .exe. Now I would like to execute this resource (program) from within within my VC++ program. Kind of like playing a wav file, except it's an exe file. Can anyone tell me how to do this or maybe point me in the right direction?
I'm trying to write a program that can combine an outside programe to my program by the time of compiling. That would give me only one file to distribute instead of making sure the user has both.
Thanks
lordpac at 2007-11-10 5:11:02 >
# 2 Re: linking 2 .exe files
Try using the ShellExecute function.
I think this will do the needful.

Hope this helps.Do let me know if it is useful.

With regards,
Anurag Sinha.
anu_rag at 2007-11-10 5:12:04 >
# 3 Re: linking 2 .exe files
I have tried that but it will only take the name of a file, not a name of a resource.
Any other suggestions?
lordpac at 2007-11-10 5:13:02 >
# 4 Re: linking 2 .exe files
I have tried that but it will only take the name of a file, not a name of a resource.
Any other suggestions?
lordpac at 2007-11-10 5:13:57 >
# 5 Re: linking 2 .exe files
In theory you can two things:

1. Use assembler. Load the resource to memory and JMP to the exe-resources entry-point or some other. Don't know how to do this. Perhaps a separate thread is needed and a lot of assembler knowledge.

2. A better way to call the embedded executable is to write the resource to the temporal folder and execute the program as any normal program (using ShellExecute or a similar method). Use DDE or some other means of communicating between the two programs.

Or perhaps your problem could be solved by zipping the two files together? Or making the other executable an additional service which is not required?
jahonen at 2007-11-10 5:15:02 >
# 6 Re: linking 2 .exe files
1. Use assembler. I've programmed a little bit in assembly but that's a little out of my league. There must be a way to do it with C++ I would think.

2. This seems like a good solution. Any ideas on how I would write the resouce to disk?

Your last suggestion would of course work,(I was planning on doing that if I could not get my way to work), but I see many possabilities if a could just have one program and not use a zipper
Thanks
lordpac at 2007-11-10 5:16:01 >
# 7 Re: linking 2 .exe files
1. Use assembler. I've programmed a little bit in assembly but that's a little out of my league. There must be a way to do it with C++ I would think.

2. This seems like a good solution. Any ideas on how I would write the resouce to disk?

Your last suggestion would of course work,(I was planning on doing that if I could not get my way to work), but I see many possabilities if a could just have one program and not use a zipper
Thanks
lordpac at 2007-11-10 5:17:07 >
# 8 Re: linking 2 .exe files
The plot is simple:

HRSRC hrsrc = FindResourceEx(hModule, RT_RCDATA, _T("exe"), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
HGLOBAL hglobal = LoadResource(hModule, hrsrc);
DWORD size = SizeOfResource(hModule, hrsrc);
LPVOID pointertodata = LockResource(hglobal);

It is not necessary to unlock the resource. The resource is freed (and the pointer made invalid) after the module which contains the resource is unloaded.

I assume you know how to write the resource to a file from here :)
jahonen at 2007-11-10 5:18:06 >
# 9 Re: linking 2 .exe files
I've gotten that far, at least using FindResourceEx and LoadResource to try to run my "exe". That did not work. But using your idea of writing to disk, I'll have to search the help to find out how to do that.Can't expect you to write my program yourself.
Thanks for the Help. You sent me on a thread of thinking, I didn't even think of....I think. ;-)

P.S. If anyone has a suggestion on how to have it "run" from my program, I'm still interested.
lordpac at 2007-11-10 5:19:03 >
# 10 Re: linking 2 .exe files
I've gotten that far, at least using FindResourceEx and LoadResource to try to run my "exe". That did not work. But using your idea of writing to disk, I'll have to search the help to find out how to do that.Can't expect you to write my program yourself.
Thanks for the Help. You sent me on a thread of thinking, I didn't even think of....I think. ;-)

P.S. If anyone has a suggestion on how to have it "run" from my program, I'm still interested.
lordpac at 2007-11-10 5:20:05 >
# 11 Re: linking 2 .exe files
Check the help for CreateProcess API function. I couldn't make out how to run resources with it directly. This problem of yours needs quite some digging into the Platform SDK. Surf to http://msdn.microsoft.com for online PSDK.
jahonen at 2007-11-10 5:21:11 >
# 12 Re: linking 2 .exe files
Help!
I've pasted your code in mine...

HRSRC hrsrc = FindResourceEx(hModule, RT_RCDATA, _T("IDR_EXE"), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
HGLOBAL hglobal = LoadResource(hModule, hrsrc);
DWORD size = SizeOfResource(hModule, hrsrc);
LPVOID pointertodata = LockResource(hglobal);

and when I debug it, nothing gets loading into memory. All var. are 00000000. I tried reading it in and then writing it to disk, but it looks like nothing gets read in. If I'm not mistaken, the resource will be in hglobal, so all I have to do is write that do disk, or am I wrong?

Thanks, guru
lordpac at 2007-11-10 5:22:09 >
# 13 Re: linking 2 .exe files
Help!
I've pasted your code in mine...

HRSRC hrsrc = FindResourceEx(hModule, RT_RCDATA, _T("IDR_EXE"), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
HGLOBAL hglobal = LoadResource(hModule, hrsrc);
DWORD size = SizeOfResource(hModule, hrsrc);
LPVOID pointertodata = LockResource(hglobal);

and when I debug it, nothing gets loading into memory. All var. are 00000000. I tried reading it in and then writing it to disk, but it looks like nothing gets read in. If I'm not mistaken, the resource will be in hglobal, so all I have to do is write that do disk, or am I wrong?

Thanks, guru
lordpac at 2007-11-10 5:23:06 >
# 14 Re: linking 2 .exe files
hModule should be handle to your application module. Get it before you call FindResourceEx:

HMODULE hModule = GetModuleHandle(NULL);

Of course, the resouce you're loading must be named "IDR_EXE". If you have another name for it, use that. The resource type must be RT_RCDATA.

The code I posted has no error checking. To get further information on errors, call GetLastError(). For Example GetModuleHandle() returns NULL if there was an error. GetLastError() returns the error code which you can look up from the Platform SDK (or the error code lookup tool) for explanation.

hglobal is a sort of pointer to the resource, but the LPVOID pointertodata returned by LockResource should be used for writing the resource to the disk.
jahonen at 2007-11-10 5:24:08 >