Shoutbox

DLL function detection (?) + weird error - 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: DLL function detection (?) + weird error (/showthread.php?tid=83141)

DLL function detection (?) + weird error by SmokingCookie on 04-13-2008 at 05:14 PM

Hi,

I have 2 questions (and it seems a bit stupid to me, to post 2 threads in less than 15 min. :P ).

1.

Is there a way to detect when a DLL function is called (so when I display a message box using "MessageBoxW" in "User32.dll")?

2.

In the following piece of code, I get some weird error (though my scirpt works perfectly):

code:
    var Contacts = Messenger.MyContacts;
    var e = new Enumerator(Contacts);
    var c = Contacts.Count;
    for(i = 0; i < c; i++) {
        e.moveNext();
        Contact = e.item();
        EmailArray[i] = Contact.Email; // This line keeps giving a "-2146823281"-error..
//        Debug.Trace(EmailArray[i]); Disabled.. Only gives the email addresses from the contactlist..
        WndEmail.Combo_AddItem("Email",Contact.Email);
    }

The error states that Contacts.Email is an empty object.
Part of the problem is my ability to understand the "for()" statement.. Which I don't really really don't understand..



2nd question solved :D
RE: DLL function detection (?) + weird error by ShawnZ on 04-13-2008 at 05:52 PM

1. it's your script... shouldn't you be able to tell other parts of it when you call a DLL yourself?

2.

try this:

var Contacts = Messenger.MyContacts;
var e = new Enumerator(Contacts);
while (e.moveNext()) {
var contact = e.item();
EmailArray[i] = contact.Email;
WndEmail.Combo_AddItem("Email",contact.Email);
}


RE: RE: DLL function detection (?) + weird error by SmokingCookie on 04-13-2008 at 06:00 PM

quote:
Originally posted by ShawnZ
1. it's your script... shouldn't you be able to tell other parts of it when you call a DLL yourself?

2.

try this:

var Contacts = Messenger.MyContacts;
var e = new Enumerator(Contacts);
while (e.moveNext()) {
var contact = e.item();
EmailArray[i] = contact.Email;
WndEmail.Combo_AddItem("Email",contact.Email);
}

1.

I actually mean, that as soon as Windows calls a function in a DLL, I'd like to know of its name and parameters.. I have DLLExp, which only reads the DLL's function names and some weird "address" thing..

2.

I'm sorry to say that your code doesn't work.. It gives me an empty combobox.. :S
RE: DLL function detection (?) + weird error by ShawnZ on 04-13-2008 at 06:03 PM

quote:
Originally posted by SmokingCookie
I actually mean, that as soon as Windows calls a function in a DLL, I'd like to know of its name and parameters.. I have DLLExp, which only reads the DLL's function names and some weird "address" thing..

you mean, when any program on the system calls a certain DLL? that's a lot harder to do...
RE: DLL function detection (?) + weird error by SmokingCookie on 04-13-2008 at 06:07 PM

Indeed.. That's why my last hope is this forum.. I am not too lazy to select the process/DLL myself, if only I could get the function names and parmeters..

And I think I'll have to live with the error :S


RE: DLL function detection (?) + weird error by felipEx on 04-13-2008 at 08:30 PM

it's a bit late for a reply (A)

quote:
Originally posted by SmokingCookie
I actually mean, that as soon as Windows calls a function in a DLL, I'd like to know of its name and parameters.. I have DLLExp, which only reads the DLL's function names and some weird "address" thing..
Have you tried with SpyStudio?
Take a look at the picture, I installed a hook (using SpyStudio) to detect when 'MessageBox' is called ;D

[Image: spystudiovs5ee6.th.png]
so, when you call 'MessageBox'  (in a script, for example) you will see the function's name and its parameters (useful when you want to learn about external application's behavior)
code:
Interop.Call('user32', 'MessageBoxW', 0, 'text', 'title', 64)


about the second question... try this:
code:
for(var e = new Enumerator(Messenger.MyContacts) ; !e.atEnd(); e.moveNext())
{
    Debug.Trace(e.item().Email);
// WndEmail.Combo_AddItem("Email", e.item().Email);   
}

:)
RE: DLL function detection (?) + weird error by matty on 04-14-2008 at 11:44 AM

code:
var EmailAddresses = new Array()
for (var e = new Enumerator(Messenger.MyContacts); !e.atEnd(); e.moveNext() ) {
    EmailAddresses.push(e.item().Email); // add the Contacts email address to the end of the array
    WndEmail.Combo_AddItem("Email", e.item().Email);
}

Or if you are as so inclined to create a loop to fill the Combo box...

code:
for (var i in EmailAddresses) {
    WndEmail.Combo_AddItem("Email", EmailAddresses[i]);
}

RE: DLL function detection (?) + weird error by SmokingCookie on 04-14-2008 at 02:52 PM

Well, thanks for the replies.. Going to make homework nouw :( :S

I'll test these codes and SpyStudio later this afternoon, or in the evening..

EDIT:: Error solved.. Thanks (again :$ ) guys :D


RE: DLL function detection (?) + weird error by Matti on 04-14-2008 at 04:13 PM

The problem with your code is that you call "e.moveNext()" at the beginning of your loop. This means that it'll start off by index 1 in the Enumerator object and will go past the end. Thus, you're actually missing the first contact and then you go past the end of the enumeration, giving you that "empty object" error. :)

In fact, there's an even better way to do this. Instead of using your numeric "i" variable in your for-loop, you can do the checks with the Enumerator and let the "i" variable increase with it. You don't even need to put it at the end of the loop yourself, you can place in the incremental statement by separating it with a comma from the "e.moveNext()"! And you can also do the same to define both the "i" and "e" variables! :P

This can give you code as short as this:

code:
for(var e = new Enumerator(Messenger.MyContacts), i = 0; !e.atEnd(); e.moveNext(), i++) {
Contact = e.item();
EmailArray[i] = Contact.Email;
WndEmail.Combo_AddItem("Email",Contact.Email);
}

Red = initial statement
Green = conditional statement
Blue = incremental statement
Just to show you how much you can simplify a piece of JScript by pushing it to the limits... :)
RE: DLL function detection (?) + weird error by SmokingCookie on 04-14-2008 at 04:19 PM

Hey, I'm a serious n00b with the for() statement :P (it just doesn't make any sense to me :S )

Well, I think I have some things to experiment with for tonight :P


RE: DLL function detection (?) + weird error by Matti on 04-14-2008 at 04:40 PM

quote:
Originally posted by SmokingCookie
Hey, I'm a serious n00b with the for() statement :P (it just doesn't make any sense to me :S )

Well, I think I have some things to experiment with for tonight :P
It's quite simple in fact. :P
  • The first bit (before your first semi-colon ";") is the initial statement. This is what will be executed at the beginning of your loop, and will only be run once. In most cases, you'll want to declare variables used for looping through arrays, enumerators,...
    In our case, we define an Enumerator and a numeric variable to keep track of the counting.
  • The second bit (between your semi-colons) is the conditional statement. Here, you have to put one condition (of course you can use && or || operators) which has to be checked after each loop, including the first one. If this is true, the loop will continue. If not, the loop will end.
    In our case, we make sure that we don't go past the end of the enumerator.
  • The last bit (after the second semi-colon) is the incremental statement. This will be executed after each loop, before the conditional statement is checked again for the next loop. It is normally used to increase the indexes, but in theory you can put anything here.
    In our case, we move the Enumerator to the next item and increase the numeric index by one.
Play around with it, you'll get the hang of it quite fast. In 90% of the cases, it's always the same type you'll use:
code:
for(var i = 0; i < MAX_INDEX; i++) { ... }
where MAX_INDEX can be "SomeArray.length" for arrays, "PlusWnd.LstView_GetCount('SomeListView')" for window list-view controls,... it all depends of the particular case you're dealing with. :P
RE: DLL function detection (?) + weird error by SmokingCookie on 04-14-2008 at 04:47 PM

Well, I came for 2 answers, I got 3, thanks :P

Your explanation looks clearer to me, than the one at MSDN :P

I assume I owe you one? :P