IonicWind Software

Aurora Compiler => Coding Help - Aurora 101 => Topic started by: Kale on November 03, 2006, 12:43:39 PM

Title: How to get argv and argc?
Post by: Kale on November 03, 2006, 12:43:39 PM
How do i get the argv and argc array using Aurora?
Title: Re: How to get argv and argc?
Post by: Ionic Wind Support Team on November 03, 2006, 01:02:52 PM
The argv array and argc count are created by the C startup routine and are not a part of the Windows OS.  You can, however, retrieve the entire command line used to start your executable using the API function GetCommandLineA/W

Here is a previous discussion on the subject:

http://www.ionicwind.com/forums/index.php/topic,59.15.html

Which includes code to parse the command line to create your own parameter array.

Paul.
Title: Re: How to get argv and argc?
Post by: Kale on November 03, 2006, 01:35:20 PM
I see, thanks.

Is there any chance of these being added natively to Aurora? as these are used alot.
Title: Re: How to get argv and argc?
Post by: sapero on November 03, 2006, 02:49:47 PM
Paul, i use modified consolestartup and winstartup where is a call to crtdll::__GetMainArgs, then argc and argv are passed to the main function.
The stack pointer is saved/restored in .bss section and i never got problems with this modification.
invoke __GetMainArgs, _argc, _argv, _env, 0
invoke main, [$_argc], [$_argv]
mov ÂÃ,  ÂÃ, [_exitcode], eax
mov ÂÃ,  ÂÃ, esp, [_stack]
...
segment .bss
$_argcÂÃ,  ÂÃ, resd 1
$_argvÂÃ,  ÂÃ, resd 1
$_envÂÃ,  ÂÃ,  resd 1

global sub main(int argc, string *argv[])
{
if (argc > 1) MessageBox(0, *(string)(argv[1]));
}


Kale, try this:
import int cdecl __GetMainArgs(int *argc, string *argv, string *environ, opt int unknown=0);

sub main()
{
int argc;
string *argv[1];
string *environ[1];
__GetMainArgs(&argc, &argv, &environ);
main2(argc, argv);
}

sub main2(int argc, string *argv[])
{
for (int a=0; a<argc; a++)
{
print("argument ",a," :", *(string)(argv[a]));
}
*argv[0] = readln();
}
Title: Re: How to get argv and argc?
Post by: Zen on November 06, 2006, 02:46:21 AM
Interesting hack Sapero. Although I do think it would be cool to have these added to Aurora. Either as an optional argument in main() or perhaps just as globals so you can access them anywhere.

Lewis
Title: Re: How to get argv and argc?
Post by: Parker on November 06, 2006, 08:18:57 AM
I agree this is something that should be built in. I like Paul's idea of GetArgCount and GetArgString. It's not hard to create a command line parser (especially for someone who created Aurora :D) but it's a really standard feature that should be included I think.
Title: Re: How to get argv and argc?
Post by: Ionic Wind Support Team on November 06, 2006, 06:01:44 PM
GetArgCount, GetArgString and GetArgStringW are now in Beta1 Rev 3.  Available this evening to a computer near you ;)
Title: Re: How to get argv and argc?
Post by: Kale on November 07, 2006, 02:03:57 AM
Quote from: Paul Turley on November 06, 2006, 06:01:44 PM
GetArgCount, GetArgString and GetArgStringW are now in Beta1 Rev 3.  Available this evening to a computer near you ;)
Very Very Cool! Thanks Paul! :D
Title: Re: How to get argv and argc?
Post by: Parker on November 07, 2006, 03:27:15 PM
Thanks, that'll be a nice addition.