Ah, it seems like you ran into the same problem every developer goes through when learning to work with Interop.Allocate and memory structures. No worries, I've had the same thing as well.
Let's have a look at the RECT structure as defined by MSDN:
code:
typedef struct _RECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT;
We first need to know the size of this structure. To do this, we make the sum of the size each individual type takes. In this case, we have 4 LONG values and each LONG takes 4 bytes, so we get 16 bytes as size.
js code:
var wndRect = Interop.Allocate(16);
We can then call GetWindowRect to fill this structure for us.
js code:
Interop.Call("user32.dll", "GetWindowRect", ChatWnd.Handle, wndRect);
As you can see, you were doing pretty well in fact!
Now we want to read the individual pieces of the memory structure. Unlike C++, a Plus! script doesn't actually "know" what structure you created, so you'll have to find out where your data is yourself and what type it is.
For instance, if we want to read the value for the left position. Looking back at the MSDN structure definition, we find that this is the first element in the structure, and that it's a LONG of 4 bytes. This means that we have to read the
DWORD on
position 0 (zero) to get the left position:
js code:
var wndLeft = wndRect.ReadDWORD(0);
On to the next element: the top position. This is the second element in the structure, thus there is
one LONG before it. This means we can find it on
position 4 in our structure, also as a DWORD. The right position will be 4 bytes further on position 8 and the bottom position will be at position 12.
js code:
var wndTop = wndRect.ReadDWORD(4);
var wndRight = wndRect.ReadDWORD(8);
var wndBottom = wndRect.ReadDWORD(12);
And there you have it! You just read a RECT structure!
For the OOP fans here, you can also do this with a nice object:
js code:
var objRect = {
left: wndRect.ReadDWORD(0),
top: wndRect.ReadDWORD(4),
right: wndRect.ReadDWORD(8),
bottom: wndRect.ReadDWORD(12)
};
[offtopic]
Blah, I've been beaten again while writing this way too long post.
Hah, at least I beat you
here!
[/offtopic]