Need help passing arguments to another dol

support for the powerpc toolchain
Post Reply
wiiNinja
Posts: 1
Joined: Thu Jul 16, 2009 11:05 pm

Need help passing arguments to another dol

Post by wiiNinja » Thu Jul 16, 2009 11:22 pm

Hello,

I'm trying to launch another .dol from my own code, and the piece of code that I got looks like this:

Code: Select all

struct __argv dolArgv;
bzero(&dolArgv, sizeof(dolArgv));
dolArgv.argvMagic = ARGV_MAGIC;
dolArgv.length = strlen(filename) + 2;
dolArgv.commandLine = malloc(dolArgv.length);
if (!dolArgv.commandLine)
{
	init_video_and_wpad();
	printf("Error creating arguments, could not allocate memory for commandLine\n");
	printf("Press any button to reboot Wii...\n");
	press_button_to_reboot();
}
strcpy(dolArgv.commandLine, filename);
dolArgv.commandLine[dolArgv.length - 1] = '\x00';
dolArgv.argc = 1;
dolArgv.argv = &(dolArgv.commandLine);
dolArgv.endARGV = dolArgv.argv + 1;
run_dol(myBuffer, &dolArgv);
This runs fine for the case that there's no argument after the path to the .dol to be launched. But assuming that the launched dol is expecting an additional argument, what needs to be changed from the code above?

I've tried a bunch of things including adding the argument to the "commandLine" and setting the "argc" to 2 (and other things) but I could not get this to work.

Also, what exactly is variable "endARGV"?

Any help is greatly appreciated.

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Need help passing arguments to another dol

Post by WinterMute » Tue Sep 22, 2009 9:40 pm

The command line should be a set of nul terninated strings, ending with a double nul. You only need to set the address of this command line and the complete length. Something like this should work.

Code: Select all

	struct __argv arg;

	arg.argvMagic = ARGV_MAGIC;
 
	arg.length = strlen(filename) + strlen(param1) + strlen(param2) + 5;
	arg.commandLine = malloc(arg.length);
 	sprintf(arg.commandline, "%s\0%s\0%s\0\0\0");
The other elements of the struct are for internal use when the crt0 startup code copies the command line to the base of heap & builds the argv array.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests