Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++ Help needed

Started by wikedgamer Dec 11, 2002 at 3:45 PM 6 replies 500+ views
Original Post
wikedgamer
wikedgamer
Using C++ (with MSVC), how can I make a program similar to a DOS prompt where I can type like ''Notepad.exe'' and the program will open Notepad? It''s just a text or console type program. Any ideas? Thanks in advance! WikedGamer
Sand_Hawk
Sand_Hawk
You want to use a console to rewrite the CMD shell for windows? Bad idea!! However, if you want to make apps that look like the DOS box, create in VC a new project and set the target to Win32 Console App.

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site
----------------(Inspired by Pouya)
niyaw
niyaw
main() {
string command;
getline(cin, command);
ShellExecute("open", command);
}

wikedgamer
wikedgamer
niyaw:


I tried that code and edited it a bit to this:


#include <iostream.h>


main()
{
float command;
float ShellExecute;
float Notepad;

cout << "Command: ";
cin >> command;

command = ShellExecute("open", "Notepad");

return 0;
}



When I compile it, I get 1 error that points to the ''command ='' line:

error C2064: term does not evaluate to a function



Any suggestions?
Synapse
Synapse
Should be including iostream not iostream.h

I am not fimilar with ShellExecute but by the way niyaw uses it, it doesn't return anything....

[edited by - Synapse on December 11, 2002 7:54:57 PM]
Palidine
Palidine
erm. it's not compiling b/c, as previously mentioned, b/c ShellExecute does not appear to return a value. beyond that, however, you have some fairly serious problems that are going to give you MASSIVE problems beyond just not compiling:

problem the 1st: ShellExecute is a library function of some sort pulled in by some header or another. for that reason, i don't understand this line:
float ShellExecute;

and this line also doesn't really make sense because you never use the variable. so why define it?:
float Notepad;

this again, has a conceptual problem even if ShellExecute did return a value. by doing it this way you are also restricting your program to only be able to run notepad, no matter what you type in. from the way in which the function was used, ShellExecute's 2nd parameter seems to be the command that you want the OS to execute:
command = ShellExecute("open", "Notepad");

as previously mentioned, ShellExecute appears to not return a value. as well, why would you assign a value to your variable "command" using cin and then immediately reassign it another value from a function?

i dunno. i guess there are a couple options.
1) use the code as it was given to you.
2) (and i'd suggest this one) you should probably spend a while going back through some basic C++ tutorials and writing some normal command line applications. my sense is that you are probably just starting out, which is great, btw. but you might want to start by tackling something a little smaller than writing your own command-line interface to an OS. that's a fairly large project and would probably serve you better as a long-term goal type of motivating force in your c++ studies.

-me

[edited by - Palidine on December 11, 2002 8:20:06 PM]

[edited by - Palidine on December 11, 2002 8:22:10 PM]
DerekSaw
DerekSaw
quote:
Original post by wikedgamer
...Any suggestions?

1. Learn up what a variable is, it helps you alot.
2. Here''s some minor fixed up of your code:

#include <iostream>
using namespace std;
int main()
{
string command;

cout << "Command: ";
getline(command, cin);

// pls look up the docs and fill in the remaining parameters
::ShellExecute("open", command, ...);
}
"after many years of singularity, i'm still searching n the event horizon" o
niyaw
niyaw
my original code was missing a few things and was intended to be pseudocode rather than a compilable sample. if you insist on something that compiles:

    
#include <iostream>

#include <string>

using namespace std;
#include <windows.h>

#include <shellapi.h>

int main() {
string command;
getline(cin, command);
ShellExecute(0, "open", command.c_str(), 0, 0, SW_SHOWNORMAL);
return 0;
}
#pragma comment(lib, "shell32.lib")


you seem to be lacking in the following areas, understanding of which is necessary for understanding the above code:
- variables and different variable types
- declaring and using functions
- function return values
- function prototypes
- strings

my suggestion to you would be to follow whatever book/tutorial you're using and not jump ahead. you'll get to the cool stuff in time.

[edited by - niyaw on December 11, 2002 10:01:07 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.