What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Help with API

Help with API
Author: Message:
pedro_cesar
Junior Member
**

Avatar

Posts: 61
35 / Male / –
Joined: Dec 2006
Status: Away
O.P. Help with API
May someone please explain (or point me in the right direction) how MsgPLus interacts with the WinApi Ex.: what functions are available and how are they used?
05-26-2007 06:13 AM
Profile E-Mail PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: Help with API
You can call almost any DLL export function with the MsgPlus! scripting.
The calling method has to be stdcall, so the Windows 32 API works fine. The function does also have to return int (if you're going to read the return value).

For example: You can call the SetWindowsHookEx function, but you won't be able to anything with it because javascript cannot handle the callbacks functions needed.

To use Win32 APIs, simply use the Interop object. The Interop object has a method/function which is called Call.
To use call in order to call any API function do like this:
code:
Interop.Call("user32.dll", "SetWindowsTextW", 0, "Hello");
The first parameter is the DLL the function is in, the second is the export name, rest are optional parameters used by the function.

Note: Always use the unicode version of Win32 APIs instead of the ANSI version. So put a W after a function to use the unicode function (only on functions whichs contains one string in its parameters, all expect GetProcAddress).

Edit: After using the DLL, you might want to free it, then simply do:
code:
Interop.FreeDll("dllname.dll");

This post was edited on 05-26-2007 at 06:50 AM by vikke.
4 8 15 16 23 42
05-26-2007 06:48 AM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Help with API
In theory, you can use any functions provided in the Win32 API. However, there are some disadvantages Plus! Live has because its scripting engine isn't yet perfect. For example, you can't register a notification for a control since there's no Control object which could have a RegisterMessageNotification function, such function only exists for the PlusWnd object. Except from that, any function should work (unless I forgot something?).

Some examples:
  • ShellExecute - Used to start a program. In this example the program "MyProg.exe" in the script folder with the parameter /JustDoIt, which should get recognized by the program.
    code:
    var Result = Interop.Call(
       /* Library to call */ "shell32",
       /* Function to call */ "ShellExecuteW",
       /* hWnd */ 0,
       /* lpOperation */, "open",
       /* lpFile */, MsgPlus.ScriptFilesPath + "\\MyProg.exe",
       /* lpParameters */ "/JustDoIt",
       /* lpDirectory */ 0,
       /* nShowCmd */, 0
    );
    if(Result <= 32) //If Result is less than or equal to 32, an error has been returned.
       Debug.Trace("ShellExecute returned an error! Result: "+Result);
    else
       Debug.Trace("ShellExecute succeeded");
  • SendMessage - Used to send a window message to a window or window control. In this example, the window caption will be changed by the WM_SETTEXT message.
    code:
    //Window
    var PlusWnd = MsgPlus.CreateWnd("Windows.xml", "WndTest");
    //String for title
    var sTitle = "My New Window";
    //DataBloc for title
    var lpTitle = Interop.Allocate((sTitle.length+1)*2);
    lpTitle.WriteString(sTitle, 0);
    //Call SendMessage with WM_SETTEXT
    var Result = Interop.Call(
       /* Library to call */ "user32",
       /* Function to call */ "SendMessageW",
       /* hWnd */ PlusWnd.Handle,
       /* WM_SETTEXT */ 0xC,
       /* wParam */ 0,
       /* lParam */ lpTitle.DataPtr
    );
    if(Result != 1) Debug.Trace("SendMessage returned an error! Result: "+Result);
  • PlusWnd.RegisterMessageNotification - Used to register a notification to a window and react on it. In this example we'll dump the new size of the window to the debug window when the user is resizing it.
    code:
    //Window
    var PlusWnd = MsgPlus.CreateWnd("Windows.xml", "WndTest");
    //Register message notification
    PlusWnd.RegisterMessageNotification(/* WM_SIZE */ 0x5, true);
    ...
    function OnWndTestEvent_MessageNotification(PlusWnd, Message, wParam, lParam) {
       if(Message == /* WM_SIZE */ 0x5) {
          var Width = lParam  & 0xFFFF; //Width is stored in low-order word of lParam
          var Height = lParam >> 16; //Height is stored in high-order word of lParam
          Debug.Trace("WndTest size: "+Width+"x"+Height);
       }
       return -1; //Let the window do its stuff with this message too
    }
Oh noees! I got beaten by vikke! :(
quote:
Originally posted by vikke
Note: Always use the unicode version of Win32 APIs instead of the ANSI version. So put a W after a function to use the unicode function (only on functions whichs contains one string in its parameters, all expect GetProcAddress).
True, I wanted to mention that but I forgot.

This post was edited on 05-26-2007 at 10:21 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
05-26-2007 06:52 AM
Profile E-Mail PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: RE: Help with API
quote:
Originally posted by Mattike
Oh noees! I got beaten by vikke! :(

No you did not, you probably explains much better than me. ;)
4 8 15 16 23 42
05-26-2007 06:54 AM
Profile E-Mail PM Find Quote Report
mickael9
Full Member
***


Posts: 117
Reputation: 3
32 / Male / Flag
Joined: Jul 2005
RE: Help with API
quote:
Originally posted by Mattike
var lpTitle = Interop.Call((sTitle.length+1)*2);
var lpTitle = Interop.Allocate((sTitle.length+1)*2);

:P
05-26-2007 09:23 AM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Help with API
quote:
Originally posted by mickael9
quote:
Originally posted by Mattike
var lpTitle = Interop.Call((sTitle.length+1)*2);
var lpTitle = Interop.Allocate((sTitle.length+1)*2);

:P
True. Fixed. :P
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
05-26-2007 10:21 AM
Profile E-Mail PM Web Find Quote Report
mickael9
Full Member
***


Posts: 117
Reputation: 3
32 / Male / Flag
Joined: Jul 2005
RE: Help with API
Also note that you don't need to use a datablock to pass a simple unicode string, you can pass it directly.
05-26-2007 05:30 PM
Profile PM Web Find Quote Report
pedro_cesar
Junior Member
**

Avatar

Posts: 61
35 / Male / –
Joined: Dec 2006
Status: Away
O.P. RE: Help with API
Many Thanks to all, this's been really useful, I'm trying to improve a script I created and submitted to the database (waiting for response though). I'm gonna go and practice now some of this stuff, I have some questions already, but I'll organize'em and ask them later in a proper way.
05-27-2007 01:03 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


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