To make such array, you basically make a structure with all elements inserted the one after the other. It's easier to explain this by code:
code:
var cButtons = 2; //The number of buttons
var pButtons = Interop.Allocate(cButtons * 8); //8 bytes per button
//First button
var nButtonID1 = 0x100; //Identifier for this button
var sButtonText1 = "Button Text 1";
var pszButtonText1 = Interop.Allocate(sButtonText1.length*2+2);
pszButtonText1.WriteString(0, sButtonText1);
pButtons.WriteDWORD(0*4, nButtonID1);
pButtons.WriteDWORD(1*4, pszButtonText1.DataPtr);
//Second button
var nButtonId2 = 0x101; //Identifier for this button
var sButtonText2 = "Button Text 2";
var pszButtonText2 = Interop.Allocate(sButtonText2.length*2+2);
pszButtonText2.WriteString(0, sButtonText2);
pButtons.WriteDWORD(2*4, nButtonID);
pButtons.WriteDWORD(3*4, pszButtonText2.DataPtr);
//Use in your structure
TASKDIALOGCONFIG.WriteDWORD(/* position here */, cButtons); //cButtons
TASKDIALOGCONFIG.WriteDWORD(/* position here */, pButtons.DataPtr); //pButtons
//After calling TaskDialogIndirect
pszButtonText1.Size = 0;
pszButtonText2.Size = 0;
pszButtons.Size = 0;
TASKDIALOGCONFIG.Size = 0;
So what you're doing here is putting the contents of all TASKDIALOG_BUTTON structures into one big structure. You'll probably want to make this a bit more flexible, such as making a function to create such a structure from a JScript Array, but don't forget to implement a way to get the pszButtonText structures so you can clear them after calling TaskDialogIndirect. Maybe do it like this: return an object with the created structure in it along with an array of all created pszButtonText structures, then you can save these results and loop through the array and clear the psz's when you're done.
Ah well, it's easier for me to make such function. Here you go:
code:
/*
FUNCTION CreateTaskDialogButtonsConfig
aButtons - Array with button texts.
nBaseID - Number to use as base for the identifiers. Optional.
Each button's ID will be set to: nBaseID + index.
Defaults to 0x100. (just an easy random number)
Return value: Object with the following syntax:
{
struct: The pButtons structure.
psz: Array of psz's which need to be destroyed after use.
}
*/
function CreateTaskDialogButtonsConfig(aButtons, nBaseID) {
nBaseID = (typeof nBaseID === 'number') ? nBaseID : 0x100;
var Result = {};
var pszArray = [];
var pButtons = Interop.Allocate(aButtons.length * 8);
for(var i=0; i<aButtons.length; i++) {
var sButtonText = aButtons[i];
var psz = Interop.Allocate(sButtonText.length*2+2);
psz.WriteString(0, sButtonText);
pszArray.push(psz);
pButtons.WriteDWORD(i*8, nBaseID + i);
pButtons.WriteDWORD(i*8+4, psz.DataPtr);
}
return {
struct: pButtons,
psz: pszArray
};
}
Usage:
code:
var aButtons = ["Text 1", "Text 2"];
var TaskDialogButtons = CreateTaskDialogButtonsConfig(aButtons, 0x100);
var pButtons = TaskDialog.struct;
var pszArray = TaskDialog.psz;
//Use in your structure
TASKDIALOGCONFIG.WriteDWORD(/* position here */, aButtons.length); //cButtons
TASKDIALOGCONFIG.WriteDWORD(/* position here */, pButtons.DataPtr); //pButtons
//After calling TaskDialogIndirect
for(var i=0; i<pszArray.length; i++) pszArray[i].Size = 0;
pButtons.Size = 0;
TASKDIALOGCONFIG.Size = 0;
Heh, you're quick at implementing code.
Although I didn't check my own function, I think you're better off trying to use my function.