ctypes pointers and SendMessage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Metalone

    #1

    ctypes pointers and SendMessage

    I would like to call
    windll.user32.S endMessageA(hwn d, win32con.WM_COM MAND, 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.S endMessageA(hwn d, 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?

  • Michele Petrazzo

    #2
    Re: ctypes pointers and SendMessage

    Metalone wrote:[color=blue]
    > I would like to call
    > windll.user32.S endMessageA(hwn d, win32con.WM_COM MAND, wParam, lParam)
    > where
    > lParam represents a pointer to an object.[/color]

    and the others?
    [color=blue]
    >
    > 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?
    >[/color]


    I don't know if you want to create a "real" C structure. If yes this is
    the wrong method:
    [color=blue][color=green][color=darkred]
    >>> class X(Structure):[/color][/color][/color]
    .... _fields_ = [("x", c_int), ]
    ....[color=blue][color=green][color=darkred]
    >>> x1 = X(1)
    >>> x1.x[/color][/color][/color]
    1[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    http://starship.python.net/crew/thel.../tutorial.html ->
    Structures and Unions

    Michele

    Comment

    • Metalone

      #3
      Re: ctypes pointers and SendMessage

      Ok, I see what I did wrong.
      I forgot to define the _fields_ variable.

      Comment

      Working...