Parameters by reference - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: Parameters by reference (/showthread.php?tid=95793) Parameters by reference by barby850717@gmail. on 11-05-2010 at 06:14 PM
Hi, I was wondering if there is any way I can pass parameters by reference. RE: Parameters by reference by Matti on 11-05-2010 at 07:29 PM
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. js code: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: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: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: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. RE: Parameters by reference by CookieRevised on 11-06-2010 at 12:12 AM
Or use COM and call the DLL procedure with a pointer to an allocated datablock using the Interop functions in Plus!.... |