Shoutbox

Could someone do me a favor and run this - 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: Could someone do me a favor and run this (/showthread.php?tid=95309)

Could someone do me a favor and run this by matty on 08-24-2010 at 03:12 PM

I just need the debug results from when a Chat Window is opened. Thanks

If it crashes I am sorry :(

js code:
var MAXLEN = 0xff;
var oChatWnd = {};
var IID_IAccessible = Interop.Allocate(0x10);
Interop.Call('ole32', 'IIDFromString', '{618736E0-3C3D-11CF-810C-00AA00389B71}', IID_IAccessible);


function OnEvent_ChatWndCreated (pChatWnd) {
    // Find the DirectUIHWND window
    EnumChildWindows(pChatWnd.Handle);
   
   
    var pAccessibleData = Interop.Allocate(4);
    if(Interop.Call('oleacc', 'AccessibleObjectFromWindow', oChatWnd[pChatWnd.Handle], 0xFFFFFFFC, IID_IAccessible, pAccessibleData) === 0) {
        var iAccessible = pAccessibleData.ReadInterfacePtr(0);
        if(iAccessible) {
            var iAccessibleChildren = Interop.Allocate(16*iAccessible.accChildCount);
            var iAccessibleChildrenFound = Interop.Allocate(4);
            if (Interop.Call('oleacc', 'AccessibleChildren', iAccessible, 0, iAccessible.accChildCount, iAccessibleChildren, iAccessibleChildrenFound) === 0){
                for (var i=0; i<iAccessibleChildrenFound.ReadDWORD(0); ++i) {
                    if (iAccessibleChildren.ReadDWORD(i*16) === 0x9) {
                        var iAccessibleChild = iAccessibleChildren.ReadInterfacePtr(i*16+8);
                        if (iAccessibleChild) {
                            Debug.Trace(iAccessibleChild.accName(0)+' : '+iAccessibleChild.accValue(0));
                        }
                    }
                }
            }
        }
    }
}

function EnumChildWindows(hWnd) {
    oChatWnd[hWnd] = 0;
    Interop.Call('user32', 'EnumChildWindows', hWnd, Interop.GetCallbackPtr('EnumChildProc'), 0);
}

function EnumChildProc(hWnd, lParam) {
    var GA_PARENT = 0x1;
    var lpClassName = Interop.Allocate(MAXLEN);
    Interop.Call('user32', 'GetClassNameW', hWnd, lpClassName, MAXLEN);
    if (lpClassName.ReadString(0) === 'DirectUIHWND') {
        oChatWnd[Interop.Call('user32', 'GetAncestor', hWnd, GA_PARENT)] = hWnd;
        return false;
    }
    return true;
}

RE: Could someone do me a favor and run this by Chrissy on 08-24-2010 at 03:19 PM

I ran it,

quote:
Script is starting
Script is now loaded and ready
Function called: OnEvent_ChatWndCreated


RE: Could someone do me a favor and run this by matty on 08-24-2010 at 03:19 PM

Did you open a Chat Window?


RE: Could someone do me a favor and run this by Eljay on 08-24-2010 at 03:20 PM

It displays nothing at all :P

quote:
Script is starting
Script is now loaded and ready
Function called: OnEvent_ChatWndCreated

RE: Could someone do me a favor and run this by Chrissy on 08-24-2010 at 03:21 PM

quote:
Originally posted by matty
Did you open a Chat Window?
Yeah, sorry it was this

quote:
Script is starting
Script is now loaded and ready
Function called: OnEvent_ChatWndCreated


edit: yeah, same as above.
RE: Could someone do me a favor and run this by matty on 08-24-2010 at 03:23 PM

Could either of you tell me what the chat window class is called? I assume the child window is the DirectUIHWND.


RE: Could someone do me a favor and run this by Chrissy on 08-24-2010 at 03:28 PM

quote:
Originally posted by matty
Could either of you tell me what the chat window class is called? I assume the child window is the DirectUIHWND.
If you tell me how I'll easy tell you :).
RE: Could someone do me a favor and run this by Eljay on 08-24-2010 at 03:29 PM

quote:
Originally posted by matty
Could either of you tell me what the chat window class is called? I assume the child window is the DirectUIHWND.

[Image: attachment.php?pid=999663]
RE: Could someone do me a favor and run this by matty on 08-24-2010 at 03:34 PM

Thanks LJ! Could you guys run this now

js code:
var MAXLEN = 0xff;
var IID_IAccessible = Interop.Allocate(0x10);
Interop.Call('ole32', 'IIDFromString', '{618736E0-3C3D-11CF-810C-00AA00389B71}', IID_IAccessible);

// A chat window will automatically open
>>>Messenger.OpenChat('test@test.com');<<<

function OnEvent_ChatWndCreated (pChatWnd) {
    var hWnd = Interop.Call('user32', 'FindWindowExW', pChatWnd.Handle, 0, 'IM Window Class', '');
    hWnd = Interop.Call('user32', 'FindWindowExW', hWnd, 0, 'DirectUIHWND', '');
   
    var pAccessibleData = Interop.Allocate(4);
    if(Interop.Call('oleacc', 'AccessibleObjectFromWindow', hWnd, 0xFFFFFFFC, IID_IAccessible, pAccessibleData) === 0) {
        var iAccessible = pAccessibleData.ReadInterfacePtr(0);
        if(iAccessible) {
            var iAccessibleChildren = Interop.Allocate(16*iAccessible.accChildCount);
            var iAccessibleChildrenFound = Interop.Allocate(4);
            if (Interop.Call('oleacc', 'AccessibleChildren', iAccessible, 0, iAccessible.accChildCount, iAccessibleChildren, iAccessibleChildrenFound) === 0){
                for (var i=0; i<iAccessibleChildrenFound.ReadDWORD(0); ++i) {
                    if (iAccessibleChildren.ReadDWORD(i*16) === 0x9) {
                        var iAccessibleChild = iAccessibleChildren.ReadInterfacePtr(i*16+8);
                        if (iAccessibleChild) {
                            Debug.Trace(iAccessibleChild.accName(0)+' : '+iAccessibleChild.accValue(0));
                        }
                    }
                }
            }
        }
    }
}

RE: RE: Could someone do me a favor and run this by Chrissy on 08-24-2010 at 03:36 PM

quote:
Script is starting
Script is now loaded and ready
Function called: OnEvent_Initialize
Function called: OnEvent_Uninitialize
Script has been stopped
Script is starting
Script is now loaded and ready

RE: Could someone do me a favor and run this by matty on 08-24-2010 at 03:38 PM

Thanks looks like I have some debugging to do...

Sucks not having access to Messenger to test while at work...


RE: Could someone do me a favor and run this by Chrissy on 08-24-2010 at 03:41 PM

Maybe use something like gotomypc?


RE: Could someone do me a favor and run this by matty on 08-24-2010 at 03:42 PM

quote:
Originally posted by Chrissy
Maybe use something like gotomypc?
Renovations. Basement is just a concreate floor. PC isn't connected. But I can RDP to the machine when it is connected.
RE: RE: Could someone do me a favor and run this by segosa on 08-24-2010 at 07:05 PM

quote:
Originally posted by matty
Thanks LJ! Could you guys run this now

js code:
var MAXLEN = 0xff;
var IID_IAccessible = Interop.Allocate(0x10);
Interop.Call('ole32', 'IIDFromString', '{618736E0-3C3D-11CF-810C-00AA00389B71}', IID_IAccessible);

// A chat window will automatically open
>>>Messenger.OpenChat('test@test.com');<<<

function OnEvent_ChatWndCreated (pChatWnd) {
    var hWnd = Interop.Call('user32', 'FindWindowExW', pChatWnd.Handle, 0, 'IM Window Class', '');
    hWnd = Interop.Call('user32', 'FindWindowExW', hWnd, 0, 'DirectUIHWND', '');
   
    var pAccessibleData = Interop.Allocate(4);
    if(Interop.Call('oleacc', 'AccessibleObjectFromWindow', hWnd, 0xFFFFFFFC, IID_IAccessible, pAccessibleData) === 0) {
        var iAccessible = pAccessibleData.ReadInterfacePtr(0);
        if(iAccessible) {
            var iAccessibleChildren = Interop.Allocate(16*iAccessible.accChildCount);
            var iAccessibleChildrenFound = Interop.Allocate(4);
            if (Interop.Call('oleacc', 'AccessibleChildren', iAccessible, 0, iAccessible.accChildCount, iAccessibleChildren, iAccessibleChildrenFound) === 0){
                for (var i=0; i<iAccessibleChildrenFound.ReadDWORD(0); ++i) {
                    if (iAccessibleChildren.ReadDWORD(i*16) === 0x9) {
                        var iAccessibleChild = iAccessibleChildren.ReadInterfacePtr(i*16+8);
                        if (iAccessibleChild) {
                            Debug.Trace(iAccessibleChild.accName(0)+' : '+iAccessibleChild.accValue(0));
                        }
                    }
                }
            }
        }
    }
}


var hWnd = Interop.Call('user32', 'FindWindowExW', pChatWnd.Handle, 0, 'IM Window Class', '');

... IMWindowClass?

RE: Could someone do me a favor and run this by matty on 08-24-2010 at 07:08 PM

quote:
Originally posted by segosa
js code:
var hWnd = Interop.Call('user32', 'FindWindowExW', pChatWnd.Handle, 0, 'IM Window Class', '');

... IMWindowClass?
I was going off of the image Eljay posted. The parent of the DirectUIHWND was IM Window Class...
RE: Could someone do me a favor and run this by roflmao456 on 08-24-2010 at 08:16 PM

I ran the (revised) code.. and I got

The automatic chatwnd opening should have been in the Initialize event btw. That's why Chrissy's debug log doesn't have the function called :P

code:
Script is starting
Script is now loaded and ready
Function called: OnEvent_ChatWndCreated
Error: unknown (code: -2147467259)
       File: test.js. Line: 20.
Function OnEvent_ChatWndCreated returned an error. Code: -2147352567

Line 20 being the debug.trace

edit: Tried the original code.. no output :P
RE: Could someone do me a favor and run this by CookieRevised on 08-24-2010 at 09:54 PM

quote:
Originally posted by segosa
var hWnd = Interop.Call('user32', 'FindWindowExW', pChatWnd.Handle, 0, 'IM Window Class', '');

... IMWindowClass?
No, that code line is correct.
"IM Window Class" is a child window of the "IMWindowClass" class window.
Got me the first time too.
RE: Could someone do me a favor and run this by matty on 08-24-2010 at 10:45 PM

Got it figured out :) With some help from Cookie

Some of the children have children of their own :)

Thanks to Cookie for writing this up while I was at my girlfriend's place :)

js code:
var sResName = GetMsgrStringResource(60052);
var IID_IAccessible = Interop.Allocate(0x10);
Interop.Call('Ole32', 'IIDFromString', '{618736E0-3C3D-11CF-810C-00AA00389B71}', IID_IAccessible);

function OnEvent_ChatWndCreated (pChatWnd) {
    var oContacts = pChatWnd.Contacts;
    if (oContacts.Count === 1) {
        var hWnd = Interop.Call('User32', 'FindWindowExW', pChatWnd.Handle, 0, 'IM Window Class', '');
        hWnd = Interop.Call('User32', 'FindWindowExW', hWnd, 0, 'DirectUIHWND', '');
   
        var pAccessibleData = Interop.Allocate(4);
        if (Interop.Call('OleAcc', 'AccessibleObjectFromWindow', hWnd, 0xFFFFFFFC, IID_IAccessible, pAccessibleData) === 0) {
            var iAccessible = pAccessibleData.ReadInterfacePtr(0);
            if (iAccessible) {
                var bStopSearch = false;
                AA_GetItems(iAccessible, new Enumerator(oContacts).item());
            }
        }
    }
   
    function AA_GetItems(iAccessible, oContact) {
        var iAccessibleChildren = Interop.Allocate(16*iAccessible.accChildCount);
        var iAccessibleChildrenFound = Interop.Allocate(4);
        if (Interop.Call('Oleacc', 'AccessibleChildren', iAccessible, 0, iAccessible.accChildCount, iAccessibleChildren, iAccessibleChildrenFound) === 0){
            for (var i=0; i<iAccessibleChildrenFound.ReadDWORD(0); ++i) {
                if (iAccessibleChildren.ReadDWORD(i*16) === 0x9) {
                    var iAccessibleChild = iAccessibleChildren.ReadInterfacePtr(i*16+8);
                    if (iAccessibleChild) {
                        if (iAccessibleChild.accChildCount) {
                            AA_GetItems(iAccessibleChild, oContact);
                        } else {
                            if (iAccessibleChild.accRole(0) === 41) {
                                if (iAccessibleChild.accName(0) === sResName) {
                                    Debug.Trace("Role: " + iAccessibleChild.accRole(0) + ", Status: " + iAccessibleChild.accState(0));
                                    Debug.Trace("'" + iAccessibleChild.accName(0) + "' : '" + iAccessibleChild.accValue(0) + "'");
                                    // Status/Name/PSM change cause the name to be updated
                                    iAccessibleChild.accValue(0) = '(XX:XX) ' + oContact.Name;
                                    Debug.Trace("'" + iAccessibleChild.accName(0) + "' : '" + iAccessibleChild.accValue(0) + "'");
                                    bStopSearch = true;
                                }
                            }
                        }
                    }
                }
                if (bStopSearch) return;
            }
        }
    }
}

// This function will read a translation string resource from Messenger located in msgslang.dll.
// If bEval (optional) is true then substrings will be filled in automatically. False by default.
function GetMsgrStringResource(nStringID, bEval) {
    var hMod = Interop.Call('Kernel32', 'LoadLibraryExW', GetMsgrFullDLLName('msgslang'), 0, 2 /* LOAD_LIBRARY_AS_DATAFILE */);
    var sBuffer = Interop.Allocate(2050);
    Interop.Call('User32', 'LoadStringW', hMod, nStringID * 1, sBuffer.DataPtr, 1024);
    Interop.Call('Kernel32', 'FreeLibrary', hMod);
    sBuffer = sBuffer.ReadString(0);
    if (bEval) sBuffer = sBuffer.replace(/\{(?:A\:)?(\d+)\}/g, function($0,$1){return GetMsgrStringResource($1,true)});
    return sBuffer;
}

// This function will return the proper fullname of the given basename of a version dependant resource dll (eg: 'msgslang.dll', 'msgslang.8.1.0068.00.dll', 'msgslang.8.5.1302.1018.dll', 'msgslang.14.0.8089.0726.dll', etc)
function GetMsgrFullDLLName(sBaseName) {
    if (Messenger.Version > 8.0) {
        var sBuffer = Interop.Allocate(2050);
        Interop.Call('Kernel32', 'GetModuleFileNameW', 0, sBuffer.DataPtr, sBuffer.Size / 2);
        Interop.Call('Version', 'GetFileVersionInfoW', sBuffer.DataPtr, 0, sBuffer.Size, sBuffer.DataPtr);
        return sBaseName + '.' + sBuffer.ReadWord(50) + '.' + sBuffer.ReadWord(48) + '.' + ('000' + sBuffer.ReadWord(54)).slice(-4) + '.' + ('0' + sBuffer.ReadWord(52)).slice(-4) + '.dll';
    } else {
        return sBaseName + '.dll';
    }
}