Shoutbox

Developers heart felt wish! - 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: Developers heart felt wish! (/showthread.php?tid=81472)

Developers heart felt wish! by matty on 02-05-2008 at 08:52 PM

Patchou please we beg of you; implement callbacks into Plus! Scripting.

Why could the following not be possible? (Looking for the technical answer, not just can't do it.)

code:
var objCallbacks = {}
    objCallbacks['EnumWindows'] = MsgPlus.CreateCallback();

Interop.Call('user32', 'EnumWindows', objCallbacks['EnumWindows'], 0);

function OnFunctionCallback(hCallback, lParam1, lParam2, lParam3, lParam4, lParam5, lParam6, lParam7, lParam8, lParam9, lParam10) {
    switch (hCallback) {
        case objCallbacks['EnumWindows'] :
            Debug.Trace(lParam1);
            return objCallbacks['EnumWindows'];
    }
}

RE: Developers heart felt wish! by vikke on 02-05-2008 at 09:10 PM

There could be problems with the parameters, because they are different (both count and size) depending on what callback you're using (or if you create your own). I don't know if it's possible in some way to solve this (well it could work if you pass parameters to the CreateCallback() method of the MsgPlus object).


RE: Developers heart felt wish! by Patchou on 02-05-2008 at 10:10 PM

matty, it's just not that simple you see... scripting functions are very different than native function. Please post back and give me a list of function for which you would need a callback, I'll try to work on something.


RE: Developers heart felt wish! by matty on 02-05-2008 at 11:37 PM

Well my preference would be all of them because that would make the scripting engine complete as far as Win32 API support.

I still don't understand the technical details as to why this cannot be incorporated.


RE: Developers heart felt wish! by Patchou on 02-06-2008 at 07:51 PM

Please give me the one thing I asked you to provide. I only need you to give me a list of functions you plan on using with callbacks so that I can check them out (for things like calling conventions). Thank you.


RE: Developers heart felt wish! by CookieRevised on 02-06-2008 at 08:24 PM

Aren't most (if not all) callback functions in the form of:
MessageCode, wParam, lParam ??

Making it actually more like:

code:
// instruct Plus! to make a (callback) function internally and let it return its address
var objCallbacks = {}
    objCallbacks['EnumWindows'] = MsgPlus.CreateCallback();

Interop.Call('user32', 'EnumWindows', objCallbacks['EnumWindows'], 0);

function OnFunctionCallback(hCallback, Message(or handle to wnd), wParam, lParam) {
    switch (hCallback) {

Making it almost the same as OnWindowidEvent_MessageNotification???

Using this 'convention'/method you would have covered almost all callbacks... (By heart I only know of only 1 callback function which uses 1 more parameter; WindowProc)

Interpreting what the parameters are (just a number or a pointer to something else) is the responsebility of the scripter, imho, just like with OnWindowidEvent_MessageNotification (?)

/me sits beside Matty on his knees begging :D
RE: Developers heart felt wish! by matty on 02-06-2008 at 08:33 PM

EnumWindows (callback: EnumWindowsProc)
InternetConnectW (callback: InternetSetStatusCallback)
EnumDisplayMonitors (callback: MonitorEnumProc)

Here is 3 off the top of my head.

quote:
Originally posted by CookieRevised
Aren't most (if not all) callback functions in the form of:
MessageCode, wParam, lParam ??

Making it actually more like:
code:
// instruct Plus! to make a (callback) function internally and let it return its address
var objCallbacks = {}
    objCallbacks['EnumWindows'] = MsgPlus.CreateCallback();

Interop.Call('user32', 'EnumWindows', objCallbacks['EnumWindows'], 0);

function OnFunctionCallback(hCallback, Message, wParam, lParam) {
    switch (hCallback) {

Making it almost the same as OnWindowidEvent_MessageNotification???

using this 'convention'/method you would have covered almost all callbacks... (By heart I only know of 1 callback function which uses 1 more parameter; WindowProc)

/me sits beside Matty on his knees begging :D


Using the many params was just to make sure all were covered WndProc who cares about we don't need Plus! scripting to subclass Windows thats just too much access to the system.
RE: Developers heart felt wish! by Eljay on 02-06-2008 at 08:35 PM

http://allapi.mentalis.org/apilist/e.shtml

Anything starting with "Enum" there :P


RE: Developers heart felt wish! by Patchou on 02-06-2008 at 08:50 PM

Alrighty, thanks for the info. You'll have it in 4.51 :).

And to answer your first question: the reason why Plus! doesn't have it yet is that for this kind of thing to work, I need to work on extra calling layers in the software to make it as much transparent as possible for the scripting world. Jsut remember that it's not because something looks easy to use in scripting that it is easy to implement. That's the whole idea :).


RE: Developers heart felt wish! by Eljay on 02-06-2008 at 08:55 PM

quote:
Originally posted by Patchou
You'll have it in 4.51 :).

:bow: :bow: :bow:
RE: Developers heart felt wish! by matty on 02-06-2008 at 08:56 PM

you are the man!

* matty wonders when we can expect 4.51...


RE: Developers heart felt wish! by Patchou on 02-06-2008 at 09:04 PM

* Patchou wonders too.... :p

Don't worry Matty, I'll bother you soon enough with aome private build to test.


RE: Developers heart felt wish! by aNILEator on 02-06-2008 at 11:54 PM

and fix some skinny stuff to <3 :->


RE: Developers heart felt wish! by vikke on 02-08-2008 at 02:46 PM

What about SetWindowLong and SetWindowsHook? I want callbacks for those.

Technical answer: When C++ is compiled native, it means that the compiler basically converted the code to assembly code. This code is much more low-level, and very difficult to read by humans (but quite easy to understand), this is also why you cannot read the source-code of any program you've downloaded. You can say it's the language your processor is reading. Different functions have different calling conventions, they are called differently in the assembly code. You won't notice this when coding C++, but the outcome is different. The compiler stores the function signature (what address, calling convention, parameters) the function has, and if your line doesn't match, the compiler prints an error. To make programming more sorted, you put these often signatures in your header file (*.h/hpp), and then include that file on the top of the actual code (*.c/cpp). For example (this is the function signature):

code:
int myfunc(int a);
Mostly compilers use the __cdecl calling convention by default (C/C++ compilers). So the compiler would read it as:
code:
int __cdecl myfunc(int a);
If you change calling convention to, let's say, __stdcall, you won't notice any difference, the function will get called as you wanted, but the assembly code is different.
When you call it in your code you'll probably use something like this:
code:
myfunc(1);
But if you do anything wrong like: (this code is wrong since the myfunc-function only has 1 parameter.)
code:
myfunc(1,2);
What I wanted to show was that the compiler check for the signature when a callback function is called. When you apply yourself to a hooking-chain or another callback function, you simply leave an address in the memory to the function you want them to call, but they cannot find your calling convention, so Microsoft said:
quote:
Let's use the __stdcall calling convention for Win32 functions.
There's a way to bypass the signature check, because you cannot get the signature (well if you know assembly, you could figure it out) after the compilation, but when Windows wants to call your function, it simply uses __stdcall. When you call an API-function with a callback (when you want Windows to call your function), you leave an address to the function position in the memory it's loaded into. It knows which parameters the function must have, because you're using a technique called function-pointers, they defined the signature of the function in Windows code, so when they call it, the signature of your function must be the same as the signature they defined for your function. If the calling convention is wrong, you'll probably get a crash or something, it won't work simply.
And JScript isn't compiled code, it's not read by your processor, it's read by an emulator executed by the processor, the JScript-code is getting parsed in real time. The JScript functions aren't stored in memory, and they cannot be because they're not actually compiled code (assembly), so Windows cannot call them without knowing how to call them, and that's quite advanced, the JScript emulator doesn't allow this (this could probably be done with a lot of research and a very hacky result, but the Win32 library isn't written for scripting). Also different parameters in a function-call have different sizes, JScript doesn't because the function doesn't actually exist (this is one of the biggest reasons JScript is easier), it changes the function when it gets called, differently depending on what size of the parameters.
Now what Patchou is going to do, is that he creates the callback in his C/C++ code (he needs to know the signature before comiling!), and when his callback gets called he's going to call the JScript emulator, because he's the one with access to it.
RE: Developers heart felt wish! by Matti on 02-08-2008 at 05:16 PM

Awesome explanation, vikke! :D Many thanks for clarifying this! :)


RE: Developers heart felt wish! by vikke on 02-08-2008 at 05:58 PM

Thanks. I was bored. :)


RE: Developers heart felt wish! by Patchou on 02-08-2008 at 05:59 PM

SetWindowLong and SetWindowsHook won't be supported by the new callback system. The restriction is that only synchronous calls made by the callee (like EnumWindows) are allowed.


RE: Developers heart felt wish! by vikke on 02-08-2008 at 06:18 PM

I was actually hoping for that, but yeah, I understand the restriction, and even if it would be implemented, it would cause a lot of delay to Messenger's windows-messages, since they have to get parsed through JScript before getting handled by the window.


RE: Developers heart felt wish! by Patchou on 02-08-2008 at 07:37 PM

yep, it would cause lots of delays and I tend to assume that if you want to go that low level, you'll prefer creating a DLL for that.


RE: Developers heart felt wish! by felipEx on 03-19-2008 at 07:24 PM

Sorry for 'reviving' this thread, but i wonder if DdeCallback can be done with 4.51 :D

Edit:
i'd like to implement a small DDE client :cheesy:


RE: Developers heart felt wish! by matty on 03-19-2008 at 08:54 PM

quote:
Originally posted by http://msdn2.microsoft.com/en-us/library/ms648742(VS.85).aspx
Remarks

    The callback function is called asynchronously for transactions that do not involve the creation or termination of conversations. An application that does not frequently accept incoming messages will have reduced DDE performance because the Dynamic Data Exchange Management Library (DDEML) uses messages to initiate transactions.

    An application must register the callback function by specifying a pointer to the function in a call to the DdeInitialize function.
Asynchronous callbacks are not supported.

From our wonderful beta docs

quote:
Remember that the use of callback functions is restricted to synchronous calls. This means that all the calls made to the callback function must be done before the callee returns. Asynchronous calls are not permitted and must not be attempted in any circumstances.

RE: Developers heart felt wish! by Patchou on 03-19-2008 at 11:47 PM

Yep sorry, no DDE allowed with the new Callback function.