How to determine what file called a c++ program?
I'm writing a C++ program for a Windows 7 user which will be the default program called when she double-clicks certain files (.ora files) and I need to know how I can essentially pass in to the program the f开发者_JAVA百科ile name [including path] that she is trying to open. Since the program won't be running at the time of file selection, I can't use mouse events to cheat... How can I have a Win32 platform C++ program figure out what file called it?
thanks, CCJ
When double-clicking a file results in opening an executable, the path and name of the file are passed as the first command line argument.
int main(int argc, char *argv[]) {
if(argc<2) return 1;
std::ifstream file(argv[1]);
// ...
}
Since the first entry in argv is the path to the executable, you are interested in the second argument, argv[1].
精彩评论