The definition for "main()" is: int main(int argn, char* argsc[], char* env[]); the first argument, the integer, is the number of c strings contained in the second argument. The first element of the second argument, argsc[0] in this case, is the FQP to the binary being executed. The third argument, optional, are c strings describing the environment that the executable is running in.
@Computergeek01, I understand what your saying but its still very vague in terms of what I need to do. I am just trying to figure a way out how to pass into the main() externally maybe from another program.
The reason why I want to do this is I need to let the program that I am writing know the difference between where the program is called from. I figured i could write a smaller program that stored the file-path of where it is on the drive and when it is executed pass this location into the main program. depending on the location the main program would execute differently.
All i think i need is an example of how to pass parameters from one program to another on windows or direct me where I can learn how to do this.
Specific rather than general information would be helpful
Let me give you a concrete example:
Let's say you have a program called test.exe.
From the console you would call it with test.exe arg1 arg2
Inside your program(test.exe) you can access the parameters with
1 2 3 4 5 6 7 8
int main(int argc, char* args[])
{
for (int i = 0; i < argc; i++)
{
cout << "Arg " << i << ": " << args[i] << "\n";
}
system("pause");
}
As long as we are talking about a console application then Thomas1965 about covered it. The only other thing worth mentioning is that if you find yourself using Unicode functions, which you should be doing in reality, then you'll save yourself some work by calling "CommandLineToArgvW()": https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx . If you're having a specific problem then tell us what it is.