I am looking at launching an XBE with command-line parameters. I decided the best way would be to use the PLD_DEMO structure. Using that I can fill in the szLauncherXBE field to test that my second app was called from my first app and I can use it to return to the first app when the second app completes or something. I can also fill the Reserved field with the command-line arguments. From what I can tell there is no way to do this using XLaunchNewImage() because it will not send the data in you LAUNCH_DATA structure to the app. Your app will start but the command-line parameters you have stored will be gone. Looking at "undocumented.h" by everlame, Team Evox, and Woodoo I determined that I need XWriteTitleInfoAndRebootA(). Using this function you can stick anything you want into the LAUNCH_DATA. You could even define your own structure as long as it is no bigger than MAX_LAUNCH_DATA_SIZE. Well, there is a slight problem with this but first I will point out how to use it for any future google drive-bys. The function declaration, which you could slap into your own code if you don't want to use undocumented.h, looks like this:
CODE
extern "C" INT WINAPI XWriteTitleInfoAndRebootA(LPVOID,LPVIOD,DWORD,DWORD,LPVOID);
I opened up xapilib.lib in vim and found the declaration within. This is what the parameters to the function are and what they mean:
CODE
pszLaunchPath = The path to the XBE you want to launch. (ex. "D:\\app2.xbe")
pszDDrivePath = This is what you want your D: drive to be mapped to. (ex. "\\Device\\CdRom0")
dwLaunchDataType = The launch data type field is what you use to determine which type of LAUNCH_DATA structure to parse. (ex. LDT_TITLE)
dwTitleId = The title id of the xbe you are launching. Could this be used as an override? (ex. 0x4D530004 if you were launching Halo 2)
pLaunchData = This is a reference to a launch data structure or you can just pass it a PLAUNCH_DATA.
Alright, so lets say I want to launch Halo 2 and I know that it is in the same directory as my xbe and that I am running off of an actual DVD. I could launch Halo 2 with the following code:
CODE
LAUNCH_DATA launchData = { LDT_TITLE };
// Halo 2 obviously won't parse this but my app will so lets pretend like Halo 2 will.
strcpy(((PLD_DEMO)&launchData)->szLauncherXBE, "MyXbe.xbe");
strcpy((char*)((PLD_DEMO)&launcData)->Reserved, "SomeCommandLineArgs"); // I can put anything I want in here. Using the PLD_DEMO structure we get 2932 bytes in the reserved field to work with which I hope would be plenty for any command-line arguments we may want to pass.
XWriteTitleInfoAndRebootA("D:\\Halo2.xbe", "\\Device\\CdRom0", LDT_TITLE, 0x4D530004, &launchData);
This code works great. I can pass anything I want to the xbe I am launching including up to a 2932 character command-line argument.
Now lets say that D:\ wasn't actually mapped to "\\Device\\CdRom0" but instead to "\\Device\\Harddrisk0\\Partition6\\Games\\MyApp" (which is equivalent to F:\Games\MyApp). Well now this code doesn't work because I am mapping D: to the wrong path. This leaves me choosing between two possible solutions:
1) Ask the user exactly where to find the XBE to be launched. This is inconvenient because you have to inform the user that they should only select it within the D: path if the actual location of the xbe is the DVD drive.
2) Query the actual mapping. This option ftw.
I'm not sure if the second option is possible but, if it is, I would love to know how to do it. Thanks to anyone that can provide any information.
As an added note, another function found within the undocumented.h header is:
CODE
extern "C" INT WINAPI XWriteTitleInfoNoReboot(LPVOID,LPVIOD,DWORD,DWORD,LPVOID);
The declaration is exactly the same as the other function. But, if you were to try to use this you would get a linker error due to the non-existent _XWriteTitleInfoNoReboot@20. This is because, should you look in xapilib.lib, it is actually _XwriteTitleInfoNoReboot@24. It has an extra parameter. Maybe it changed after undocumented.h was produced. Anyway, the extra parameter is after pszDDrivePath and it is DWORD fAllowDDriveMapping. It seems to specify whether or not the D drive can be mapped. I was slightly hopeful that if you sent a 0 into it the pszDDrivePath parameter would be ignored and it would use the current mapping. It seems that it does cause pszDDrivePath to be ignored but it doesn't use the current mapping. I am not absolutely sure but I believe it forces the mapping to be the DVD drive no matter what. I don't really see how that parameter is useful.
On top of that I am not sure how to make the Title launch once you are done with this function besides sending the console a warm reboot. Does anyone know anything more about this function?