What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Parameters by reference

Parameters by reference
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Parameters by reference
There's no such thing as passing arguments by reference in JScript. Instead, depending on the variable type, variables are changed or recreated. This is what we call "immutable" types.

For example, the string type is immutable: you can't change its value after you create one. Instead, all operations you do on the string actually create a new string:
js code:
var string = "Hello";
string += " world";
In this example, by appending "world" to string, you create a new string "Hello world" instead of changing it. The effect isn't very noticeable here, but it is when you use the value in more than one place.
js code:
var obj = {
    foo: "bar"
};
var string = obj.foo; // string holds "bar"
string += "tender"; // string is now a new string "bartender"
// obj.prop hasn't changed and is still "bar"
Here, an object with a string property is defined and then the property value is assigned to a variable. When an operation is performed on this variable, a new string is created which means that the object property stays intact. Therefore you don't have to worry about the object properties accidentally being changed because you're changing a variable holding a property.

The basic value types in JScript are immutable: number, string, boolean,... However objects an functions are pointer types, meaning they are always passed by reference.
js code:
var obj = {
  foo: "bar"
};
var newobj = obj; // newobj now also points to obj
newobj.foo = "bartender";
//obj.foo has also changed to "bartender"
Instead of copying the data from obj to a new object, newobj just points to the same data as obj. Therefore, changing a property on newobj also changed obj since they're exactly the same.

Now, a possible solution to your problem would be to pass the string argument as a property of a containing object and let your DLL change the property on that object instead. When your DLL function finishes, the data in the JScript object should be changed by the DLL, allowing you to read the new string value from the object. Your script would look something like this:
js code:
var obj = {
   foo: "bar"
};
var x = new ActiveXObject("MyScript.MyClass");
x.DoIt( obj );
// obj.foo nows hold the changed value
I don't know how you implemented your DLL interactions or how a JScript object is received in the DLL function - I haven't used DLLs a lot in my own scripts. I believe this should get you started. :)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-05-2010 07:29 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Parameters by reference - by barby850717@gmail. on 11-05-2010 at 06:14 PM
RE: Parameters by reference - by Matti on 11-05-2010 at 07:29 PM
RE: Parameters by reference - by CookieRevised on 11-06-2010 at 12:12 AM


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