Passing arguments to another .DOL?
November 27, 2010 08:02PM

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


struct __argv dolArgv;
bzero(&dolArgv, sizeof(dolArgv));
dolArgv.argvMagic = ARGV_MAGIC;
dolArgv.length = strlen(filename) + 2;
dolArgv.commandLine = malloc(dolArgv.length);
if (!dolArgv.commandLine)
printf("Error creating arguments, could not allocate memory for commandLine\n");
printf("Press any button to reboot Wii...\n");
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: Passing arguments to another .DOL?
November 27, 2010 08:05PM
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:
   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.
Sorry, you can't reply to this topic. It has been closed.