What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [WHAT??] Array pointers

[WHAT??] Array pointers
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [WHAT??] Array pointers
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. :P Although I didn't check my own function, I think you're better off trying to use my function. :)

This post was edited on 08-20-2008 at 07:19 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-20-2008 07:03 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[WHAT??] Array pointers - by SmokingCookie on 08-20-2008 at 04:28 PM
RE: [WHAT??] Array pointers - by Eljay on 08-20-2008 at 04:43 PM
RE: [WHAT??] Array pointers - by SmokingCookie on 08-20-2008 at 04:57 PM
RE: [WHAT??] Array pointers - by Matti on 08-20-2008 at 07:03 PM
RE: [WHAT??] Array pointers - by SmokingCookie on 08-20-2008 at 08:05 PM
RE: [WHAT??] Array pointers - by Matti on 08-22-2008 at 10:36 AM
RE: [WHAT??] Array pointers - by Eljay on 08-22-2008 at 11:40 AM
RE: [WHAT??] Array pointers - by Matti on 08-22-2008 at 11:57 AM
RE: [WHAT??] Array pointers - by andrewdodd13 on 08-22-2008 at 03:53 PM
RE: [WHAT??] Array pointers - by Matti on 08-22-2008 at 04:04 PM
RE: [WHAT??] Array pointers - by SmokingCookie on 08-22-2008 at 04:05 PM
RE: [WHAT??] Array pointers - by Matti on 08-22-2008 at 04:50 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On