Hi, I want open a program through C++. Ex. Like I compile the code and when I do it opens up Internet Explorer. Is this possible to do? Would I use a fin.open?
I've found this code and tried it. It does work, but I would like it to automatically open it without having to be specified.
In the code above I have to actually write iexplore into the compiler to have it open Internet Explorer. But I want the compiler to open Internet Explore right when the compiler runs without have to type anything in. Just run & compile then Internet Explorer Opens up. Does that make sense?
1) Don't use conio.h ffs.
2) Why are we using sprintf, gets, and cout in the same program? This is C++.
3) system will work but you might as well use batch commands at that point. This is a native program so we should use native calls if possible, not some function that executes commands indirectly (which is a huge security hole anyways).
4) What the hell is fin.open? There is no predefined object called fin.
5) Even if there was a predefined object called fin (assuming its of type ifstream), the open function does not open the file you think it does. It opens the files contents and read / writes to it.
6) When you double click an executable file, it doesn't "open" the file. It creates a new process with dedicated memory just for that program, loads the program into memory, and begins processing the programs stored instructions (or a similar process. May not be exact. I'll have to look at some documentation for exact process.) You have to use an OS-specific function provided by the actual OS API. To do this on Windows, you need to call the CreateProcess function documented here: http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx
Ironically, there is actually an OpenProcess function that will give you a handle to an already running process. This is relative to accessing a file that is already stored on your hard drive. To open something, it must already exist. You must Create your process in order to Open it. Get it?
7 and most important) There is actually a more correct way to start a web browser natively other than hardcoding the location of iexplore.exe and starting it (which is STUPID. I do not EVER want to see ANYONE do that. I get pissed off when I have a program open Internet Explorer over my default browser which is STUPID). Some suggest that you should use WinAPI's ShellExecute, however you can find the default browser in registry and execute it from there which I think would be more correct in our case.
Thanks for both replies, but I'm still kind of new so I don't know a lot of function calls and stuff. As for helios I mean the program the .exe that the compiler creates. I'd also like to be able to choose how many Internet Explorers open, maybe use a count function and choose the amount of times it opens.
Algorithms, you need to learn how to use the language first. I suggest you also learn the basic structure of how a computer works, how an OS works, and how a program works inside of the OS. A good assembly book will often explain most of these before hand of teaching.
That's excessive, computerquip, and... how does something so overblown really help? A book on Assembly will only discourage the OP, as while it could teach him/her all he/she needs to know, and more provided he/she had the patience... no.
However, computerquip, essentially, is right. Algorithms... you... seem to have some trouble differentiating between a compiler and the produced executable automatically. That's a problem. I don't wish to humiliate you in any way, but... you have quite some learning to do before attempting to use any element of the Windows API. Here's a site I pulled up in a few seconds. http://computer.howstuffworks.com/pc4.htm
I wasn't saying he should learn assembly, I was saying that the essence of what is the basic requirements of writing assembly is very helpful for everday programming and is often found in the beginning of an assembly book. I also hate referencing a newbie to WinAPI since he will most likely cling to it like its his blankey. Being Windows-only tends to come from these situations. They won't use cross-platform libraries or more feature filled libraries because all they want to learn is the WinAPI because they think its hot shit.
You want him to use a cross-platform library to launch a single platform application?
I'm all for portability, but really, the right tool for the right job.
It depends. It doesn't take much to make your basic assembly program (however easy it is to also cause your program to crash and burn). But to understand what assembly is doing when you type in add eax, 3;, you need to understand all that I described.
@ helios:
WTF did you EVEN read I wrote? Where did I say you should never use WinAPI? I didn't of course, I just mentioned that newbies tend to cling to it for everything, even non-OS-specific function calls which is why I don't like telling a newbie to just go read the WinAPI, especially for GUI libraries.
Alright guys I appreciate all the info and help. As for programming I said I was new not a noob, I have a teacher at my college who's the Hitler of C++ programming and she is crazy hard with C++, but because of her teaching methods I'm learning C++ quite well. I have written plenty of programs so I don't need to go to a book. I have written programs that tell you all sorts of math questions and calculations, interest rates and loan amounts, and calenders..I totally get the programming I'm just trying to widen my understanding of it and trying to take on more complicated programming, like working with the stuff I discussed above. Anyways I am somewhat new to the windows based programming with C++, yet I was able to write a program that could delete any file I specified just by opening the program, so I do get it. So how would i do the above, I'm somewhat familiar with some of the functions above, but I'd love to be able to use and understand them.
Well she gives us very difficult projects and only brushes on the stuff that we will be encountering in our projects. Then when we are working on our projects she expects us to tare apart our books looking for every function and answer. She doesn't give us examples of the projects like my other teachers have done, she just expects you to dig through the book and find stuff even if that means reading the 50 page chapters 10x through. But because of this I've memorized a lot of stuff and have learned C++ well. I took Python before this and didn't understand it like I do with C++. I can do 5x more with C++ then I could with Python.