Page 1 of 1

ProgramParameter and argument passing question:

Posted: Sat Nov 08, 2003 11:07 pm
by Akuma no Houkon
I have the following C++ declared function:

Usage

Code: Select all

void Init(int *argcp, char **argv);
argcp
A pointer to the program's unmodified argc variable from main.
argv
The program's unmodified argv variable from main.

Now from what I gather, argcp and argv are somehow connected to the command line arguments in languages like C++. I couldnt get any more information than that. I have no idea what to pass to this function or how. Everything I try results in purebasic crashing.

Do any of you know how I would properly call this function via purebasic?

Posted: Sat Nov 08, 2003 11:48 pm
by Karbon
argc is the number of command line arguments passed - argv are the values themselves.

This is an example that I think might work..

If you execute something on the command line line :

Code: Select all

myprogram -o outfile.txt
then you might call it in PB as

Code: Select all


argc.l = 2

argv.s = "-o outfile.txt"

init(*argc,argv)

I'm pretty sure PB passes strings as pointers already but if not then just pass a pointer to the string instead of the string itself.

Hope that helps!

Posted: Sun Nov 09, 2003 12:02 am
by freak
argv is a pointer to a pointer, which usually indicates an array of pointers.
My guess is this:

Code: Select all

Dim argv.s(1)

argv(0) = "-o"
argv(1) = "outfile.txt"

argcp = 2

Init(@argcp, @argv())
In PB, a stringarray is an array of stringpointers.

@Karbon:

*argc doesn't give you the address of argc, it creates a new pointer,
that points to NULL. You have to use the '@' here.

Timo

Posted: Sun Nov 09, 2003 12:12 am
by Karbon
Ahh, gotcha.. Thanks!

Posted: Sun Nov 09, 2003 12:19 am
by Akuma no Houkon
Thank you freak. I dont know if the code actually passes the paramaters properly (because I dont use any), but calling the function using the above example works.

The C++ jargon has always been cryptic to me, Thank You.