struct module usage

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

    struct module usage

    Hi!

    I'm trying to send a message from a Python script to a Scite window via
    win32gui.SendMe ssage() I'm trying to pack the commands using the struct
    module. However, I can't figure out why Scite isn't responding as I
    expect. The SendMessage is returning 0.

    I've searched Google and haven't found anything that would help me.
    There was a discussion about this same thing about 2 years ago and the
    poster solved the problem using calldll. I checked last night and
    calldll is available only for Python 2.1, while I'm using 2.3.

    Here's a snippet from the code:

    #####
    import win32api, win32gui, win32con
    import sys
    import struct

    SDI = win32api.Regist erWindowMessage ("SciTEDirector Interface");
    w = win32gui.GetWin dow(win32gui.Ge tDesktopWindow( ),win32con.GW_C HILD)

    while w:
    res = 0;
    res = win32gui.SendMe ssageTimeout(w, SDI, 0, 0,
    win32con.SMTO_N ORMAL, 1000)
    if res[1] != SDI:
    w = win32gui.GetWin dow(w, win32con.GW_HWN DNEXT)
    else:
    break
    n = len("goto:20") + 1
    s = struct.pack(`n` + "sii", "goto:20,3" , 9, 0)

    res = win32gui.SendMe ssage(w, win32con.WM_COP YDATA, s, SDI)
    #####

    I've tried almost every combination on the struct format.

    TIA,

    --
    Andres Rosado
    Email: andresr@despamm ed.com
    ICQ: 66750646
    AIM: pantear
    Homepage: http://andres980.tripod.com/

    We make the standards and we make the rules.
    -- Standards; The Jam

  • Mark Hammond

    #2
    Re: struct module usage

    BW Glitch wrote:
    [color=blue]
    > Hi!
    >
    > I'm trying to send a message from a Python script to a Scite window via
    > win32gui.SendMe ssage() I'm trying to pack the commands using the struct
    > module. However, I can't figure out why Scite isn't responding as I
    > expect. The SendMessage is returning 0.
    >
    > I've searched Google and haven't found anything that would help me.
    > There was a discussion about this same thing about 2 years ago and the
    > poster solved the problem using calldll. I checked last night and
    > calldll is available only for Python 2.1, while I'm using 2.3.
    >
    > Here's a snippet from the code:
    >
    > #####
    > import win32api, win32gui, win32con
    > import sys
    > import struct
    >
    > SDI = win32api.Regist erWindowMessage ("SciTEDirector Interface");
    > w = win32gui.GetWin dow(win32gui.Ge tDesktopWindow( ),win32con.GW_C HILD)
    >
    > while w:
    > res = 0;
    > res = win32gui.SendMe ssageTimeout(w, SDI, 0, 0,
    > win32con.SMTO_N ORMAL, 1000)
    > if res[1] != SDI:
    > w = win32gui.GetWin dow(w, win32con.GW_HWN DNEXT)
    > else:
    > break
    > n = len("goto:20") + 1
    > s = struct.pack(`n` + "sii", "goto:20,3" , 9, 0)
    >
    > res = win32gui.SendMe ssage(w, win32con.WM_COP YDATA, s, SDI)
    > #####[/color]

    Are you sure you are sending the correct message with the correct
    params? The Windows doc for WM_COPYDATA say wparam should be a hwnd,
    and lparam should be the COPYDATASTRUCT. It appears you are sending the
    struct in wparam, and a custom message integer as wparam.

    Further, the COPYDATASTRUCT contains pointers, not char arrays. Your
    struct code will need to be more complicated. Something like:

    import struct, array
    int_buffer = array.array("L" , [0])
    char_buffer = array.array("c" , "the string data")
    int_buffer_addr ess = int_buffer.buff er_info()[0]
    char_buffer_add ress, char_buffer_siz e = char_buffer.buf fer_info
    copy_struct = struct.pack("pL p", # dword *, dword, char *
    int_buffer_addr ess,
    char_buffer_siz e, char_buffer_add ress)
    # find target_hwnd somehow.
    win32gui.SendMe ssage(w, WM_COPYDATA, target_hwnd, copy_struct)

    Mark.

    Comment

    Working...