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

[Scripting Example] GetUserName
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
O.P. [Scripting Example] GetUserName
This example shows how to use the following:
Interop.Call
Interop.Allocate

code:
function GetUserName(){
   /*
      Allocate memory needed to store the returned username.
      Why do we need to use (2*(100)+2) for the size of the allocated memory?
          We do this because the maximum length of the returned string is
          100 characters (changes with different APIs). Since these are
          handled in Unicode we need to multiply the size by 2. Now the
          reason we add 2 is for a null character in unicode.

                     (Unicode*(MaxLength)+NullTerminatedString)
   */


// Thanks Cookie for pointing out that its actually UNLEN+1 and UNLEN is 256
   var sBuffer = Interop.Allocate(2*(256)+2);
// Thanks LJ I forgot I needed this.
   var lBuffer = Interop.Allocate(4);
   lBuffer.WriteDWORD(0, 255);
   Interop.Call('advapi32.dll', 'GetUserNameW', sBuffer, lBuffer);

   Debug.Trace('sBuffer: '+sBuffer.ReadString(0));

// Free the memory we allocated
   sBuffer.Size = 0;
   lBuffer.Size = 0;
}

This post was edited on 06-29-2006 at 04:50 PM by matty.
06-29-2006 03:30 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Scripting Example] GetUserName - by matty on 06-29-2006 at 03:30 PM
RE: [Scripting Example] GetUserName - by JonnyT on 06-29-2006 at 03:46 PM
RE: [Scripting Example] GetUserName - by matty on 06-29-2006 at 03:49 PM
RE: [Scripting Example] GetUserName - by Eljay on 06-29-2006 at 04:03 PM
RE: [Scripting Example] GetUserName - by matty on 06-29-2006 at 04:04 PM
RE: [Scripting Example] GetUserName - by CookieRevised on 06-29-2006 at 04:40 PM
RE: [Scripting Example] GetUserName - by JonnyT on 06-29-2006 at 04:41 PM
RE: [Scripting Example] GetUserName - by matty on 06-29-2006 at 04:42 PM
RE: [Scripting Example] GetUserName - by matty on 06-29-2006 at 05:14 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