473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

struct module usage

Hi!

I'm trying to send a message from a Python script to a Scite window via
win32gui.SendMessage() 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.RegisterWindowMessage("SciTEDirectorInter face");
w = win32gui.GetWindow(win32gui.GetDesktopWindow(),win 32con.GW_CHILD)

while w:
res = 0;
res = win32gui.SendMessageTimeout(w, SDI, 0, 0,
win32con.SMTO_NORMAL, 1000)
if res[1] != SDI:
w = win32gui.GetWindow(w, win32con.GW_HWNDNEXT)
else:
break
n = len("goto:20") + 1
s = struct.pack(`n` + "sii", "goto:20,3", 9, 0)

res = win32gui.SendMessage(w, win32con.WM_COPYDATA, s, SDI)
#####

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

TIA,

--
Andres Rosado
Email: an*****@despammed.com
ICQ: 66750646
AIM: pantear
Homepage: http://andres980.tripod.com/

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

Jul 18 '05 #1
1 2254
BW Glitch wrote:
Hi!

I'm trying to send a message from a Python script to a Scite window via
win32gui.SendMessage() 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.RegisterWindowMessage("SciTEDirectorInter face");
w = win32gui.GetWindow(win32gui.GetDesktopWindow(),win 32con.GW_CHILD)

while w:
res = 0;
res = win32gui.SendMessageTimeout(w, SDI, 0, 0,
win32con.SMTO_NORMAL, 1000)
if res[1] != SDI:
w = win32gui.GetWindow(w, win32con.GW_HWNDNEXT)
else:
break
n = len("goto:20") + 1
s = struct.pack(`n` + "sii", "goto:20,3", 9, 0)

res = win32gui.SendMessage(w, win32con.WM_COPYDATA, s, SDI)
#####


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_address = int_buffer.buffer_info()[0]
char_buffer_address, char_buffer_size = char_buffer.buffer_info
copy_struct = struct.pack("pLp", # dword *, dword, char *
int_buffer_address,
char_buffer_size, char_buffer_address)
# find target_hwnd somehow.
win32gui.SendMessage(w, WM_COPYDATA, target_hwnd, copy_struct)

Mark.

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gordon Scott | last post by:
Hi All, I've got a problem I'm seeing when trying to use the struct module to send data to a different machine. Actually I'm making a condensed file that gets transferred to and read on a BREW...
2
by: Angelo Secchi | last post by:
I'm trying to use the unpack method in the struct module to parse a binary file without success. I have a binary file with records that include many fields for a total length of 1970. Few days ago...
0
by: Josiah Carlson | last post by:
Good day everyone, I have produced a patch against the latest CVS to add support for two new formatting characters in the struct module. It is currently an RFE, which I include a link to at the...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
3
by: Sudheer Gupta | last post by:
Hi, I am having trouble using C struct in python. Hope anyone can help me out ... Say, I have my C struct as typedef struct call { struct call *next;
2
by: Jansson Christer | last post by:
Hi all, I have discovered that in my Python 2.4.1 installation (on Solaris 8), struct.pack handles things in a way that seems inconsistent to me. I haven't found any comprehensible...
4
by: Robert Kern | last post by:
Ethan Furman wrote: Right. I believe (but could be wrong) that "char" is defined to be one byte, but that "short", "int", "long", and "long long" are defined as "at least as big as the previous...
2
by: Anish Chapagain | last post by:
Hi, I have Structure in C, program and the structure is being used with various function inside C coding but am getting undefined referenced to global method and few of them too uses the sturct...
4
by: Ed | last post by:
Hi, guys, In C language manner, we need to put a "struct" token before one struct variable declaration like following. <code> struct Apple { float Price; };
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.