Next question :)
I have:
local GetWindowThreadProcessId = alien.User32.GetWindowThreadProcessId
GetWindowThreadProcessId:types{ret = 'long', abi = 'stdcall', 'long', 'pointer'}
The 'long' is input, it's a handle to the window, the 'pointer' is a pointer to the variable that receives the identifier.
My problem is that it is a pointer and it should point to an integer/long. Lua is dinamically typed. How do I make something to point to an integer typed variable? How do I create a pointer at all??
I can create a userdata typed variable
local pointhere = alien.buffer(4)
and do a call to
local tid = GetWindowThreadProcessId(hwnd_mywindow, pointhere)
The value in 'tid' is okay (it contains the threadid) but the value in 'pointhere' is unusable. It should store the processid, but I cannot cast it to an int/long. Alien has something (alien.toint or alien.tolong) that should do it but it fails with a very funny error message:
lua: test.lua:32: bad argument #1 to 'toint' (userdata expected, got userdata).
Any idea?
EDIT: Okay, just to show that I'm smart and capable of improving myself, I'll answer my own question :D
Oh, yes, did I mention that I'm humble, too? :D
So, if anyone else is interested, the method is the following:
local pointhere = alien.buffer(4)
-- this creates a 4-byte buffer
local tid = GetWindowThreadProcessId(hwnd_mywindow, pointhere)
-- this fills tid and our 4-byte buffer
local long_at_pointhere = pointhere:get(1, 'long')
-- this tells that I want x bytes forming a 'long' value and starting at the first byte of the
-- 'pointhere' buffer to be in 'long_at_pointhere' variable and let its type be 'long'
I hope this helps those who meet the same difficulties I did. I there are any, of course.
Edited 1 time(s). Last edit at 01/29/2010 03:00AM by gemisigo.