Simple compilation question

Hi guys,

Sadly I've got no C++ installed and now I need a very simple program. I don't want to install it because it uses a huge amount of space and currently I've got only 2Gb left on the windows partition (Win7). So, could anyone compile me this exe? Here's the only thing I want:

A simple exe which starts another exe in the SAME folder. The other exes name is moch.exe. No other thing, just this one.

Thank you!
Last edited on
A minimal Cygwin installation with just gcc and what it needs should take a lot less than 2GB.
Or you could just make a simple batch script for that task
The second problem is that I don't know c++ :)

Simple batch isn't good for me cuz I can't convert it to exe. I doN't really know what 'Cygwin' is, but if you can help me how to write it I would install it :)

And why I want it? I think now you ask it. Currently I'm using a script language, called AutoIT. The exe of the AutoIT is not protectable, however, I've got some other ideas this is why I need the exe written in a common laguage.
You can try online C++ compilers, for ex. this one:
http://www.comeaucomputing.com/tryitout/
Just found in google.
Wow, it's cool - but I still don't know how to start from the same dir :)
http://www.mediafire.com/?eu4l8i8kl8k5lk1

There you go. It's pretty simple but will do the trick.

One thing I will say; you should be careful when asking around for someone to make you an exe. If you head to the wrong forum, no doubt someone will send a virus your way.

In light of this, I feel obligated to provide the source code for this file, so here it is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <windows.h>

int main(int argc, char* argv[])
{
	STARTUPINFO sinfo;
	PROCESS_INFORMATION pinfo;

	size_t ret = 0;

	memset(&sinfo, 0, sizeof(STARTUPINFO));
	memset(&pinfo, 0, sizeof(PROCESS_INFORMATION));

	sinfo.cb = sizeof(STARTUPINFO);

	if( !(CreateProcess(L".\\moch.exe",
		               L" ", 0, 0, false,
					   CREATE_DEFAULT_ERROR_MODE, 0,0,
					   &sinfo, &pinfo )))
	{
		std::cout << "moch_loader: Create Process failed\n";
		
		ret = GetLastError();
		std::cout << "moch_loader: Return from CreateProcess: " << ret << std::endl;
	} // if
	
	std::cout << "moch_loader: Return value: " << ret << std::endl;
	
	// Release handles
	CloseHandle(pinfo.hProcess);
	CloseHandle(pinfo.hThread);

	return ret;
}


EDIT: The indentation screwed up a bit on the code there and I'm too lazy to fix it. Also, this needs to be run from the directory where the moch.exe file lives.
Last edited on
@iHutch
Good code, but you should determine the current working directory first. That's a frequent trap in file system programming.
Cheers Shadow. Not sure what you mean about determining the directory though. Can you elaborate? I'll be happy to amend to code and chuck up a new version.
Well, my english spelling isn't good -.-
I mean the process call will fail if the file system has another working directory registered as currently active instead of the application ones.

We can extend your code to something like that:
1
2
3
4
5
6
7
8
std::string app = argv[0]; // here we take the directory of our app - so we need an extra function to extract only the directory at this place ...
if(app.c_str()[app.size() - 1] != '\\') // adding trailing backslash
    app += '\\';
app += "moch.exe"; // our target process call
if( !(CreateProcess(L(app),
		               L" ", 0, 0, false,
					   CREATE_DEFAULT_ERROR_MODE, 0,0,
					   &sinfo, &pinfo )))

That's pseudo code, didn't compile that :-P
Last edited on
I get you.

I'll amend it when I get home and upload a new version with the extra check in.

Thanks again.
Topic archived. No new replies allowed.