What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Developers heart felt wish!

Developers heart felt wish!
Author: Message:
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
Joined: May 2006
RE: Developers heart felt wish!
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.

This post was edited on 02-08-2008 at 03:25 PM by vikke.
02-08-2008 02:46 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Developers heart felt wish! - by matty on 02-05-2008 at 08:52 PM
RE: Developers heart felt wish! - by vikke on 02-05-2008 at 09:10 PM
RE: Developers heart felt wish! - by Patchou on 02-05-2008 at 10:10 PM
RE: Developers heart felt wish! - by matty on 02-05-2008 at 11:37 PM
RE: Developers heart felt wish! - by Patchou on 02-06-2008 at 07:51 PM
RE: Developers heart felt wish! - by CookieRevised on 02-06-2008 at 08:24 PM
RE: Developers heart felt wish! - by matty on 02-06-2008 at 08:33 PM
RE: Developers heart felt wish! - by Eljay on 02-06-2008 at 08:35 PM
RE: Developers heart felt wish! - by Patchou on 02-06-2008 at 08:50 PM
RE: Developers heart felt wish! - by Eljay on 02-06-2008 at 08:55 PM
RE: Developers heart felt wish! - by matty on 02-06-2008 at 08:56 PM
RE: Developers heart felt wish! - by Patchou on 02-06-2008 at 09:04 PM
RE: Developers heart felt wish! - by aNILEator on 02-06-2008 at 11:54 PM
RE: Developers heart felt wish! - by vikke on 02-08-2008 at 02:46 PM
RE: Developers heart felt wish! - by Matti on 02-08-2008 at 05:16 PM
RE: Developers heart felt wish! - by vikke on 02-08-2008 at 05:58 PM
RE: Developers heart felt wish! - by Patchou on 02-08-2008 at 05:59 PM
RE: Developers heart felt wish! - by vikke on 02-08-2008 at 06:18 PM
RE: Developers heart felt wish! - by Patchou on 02-08-2008 at 07:37 PM
RE: Developers heart felt wish! - by felipEx on 03-19-2008 at 07:24 PM
RE: Developers heart felt wish! - by matty on 03-19-2008 at 08:54 PM
RE: Developers heart felt wish! - by Patchou on 03-19-2008 at 11:47 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