ctypes pointers and SendMessage

M

Metalone

I would like to call
windll.user32.SendMessageA(hwnd, win32con.WM_COMMAND, wParam, lParam)
where
lParam represents a pointer to an object.

And also convert this pointer back to an object reference inside of
wnd_proc
def wnd_proc(hwnd, msg, wParam, lParam):

So something like this:
class X(Structure):
def __init__(self, x):
self.v = x

x = X(1)
windll.user32.SendMessageA(hwnd, WM_COMMAND, 4000, addressof(x))

def wnd_proc(hwnd, msg, wParam, lParam):
if msg == WM_COMMAND and wParam == 4000):
x = X.from_address(lParam)
print x.v

Unfortunately, this does not work.

Also to my surprise the following does not work:
x1 = X(1)
x2 = X.from_address(addressof(x1))
addressof(x1) == addressof(x2) --> True
but
x2.v --> 'object has no attribute v'
x1.v --> 1

Also this does not work as I expect.
p = pointer(x)
p[0].v --> 'object has no attribute v'.

What am I doing wrong?
 
M

Michele Petrazzo

Metalone said:
I would like to call
windll.user32.SendMessageA(hwnd, win32con.WM_COMMAND, wParam, lParam)
where
lParam represents a pointer to an object.

and the others?
And also convert this pointer back to an object reference inside of
wnd_proc
def wnd_proc(hwnd, msg, wParam, lParam):

So something like this:
class X(Structure):
def __init__(self, x):
self.v = x

What am I doing wrong?


I don't know if you want to create a "real" C structure. If yes this is
the wrong method:
.... _fields_ = [("x", c_int), ]
....
http://starship.python.net/crew/theller/ctypes/tutorial.html ->
Structures and Unions

Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top