Page 1 of 1

Need help passing arguments to another dol

Posted: Thu Jul 16, 2009 11:22 pm
by wiiNinja
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.

Re: Need help passing arguments to another dol

Posted: Tue Sep 22, 2009 9:40 pm
by WinterMute
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.