473,769 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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: an*****@despamm ed.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 2276
BW Glitch wrote:
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)
#####


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.

Jul 18 '05 #2

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

Similar topics

3
3650
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 enabled cell-phone, essentially I'm trying to format content as if it were being streamed over a socket. So I am trying to write a string by first sending a two-byte length of the
2
2061
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 I was suggested by the list to use the struct module to parse it using the following code in the hypothesis that for each records I have just two fields: import struct fmt='10s1960s' size=struct.calcsize(fmt)
0
2303
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 end of this post. Please read the email before you respond to it. Generally, the struct module is for packing and unpacking of binary data. It includes support to pack and unpack the c types: byte, char, short, long, long long, char, *, and...
18
3051
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 a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
3
3209
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
10760
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 documentation over known issues with Python 2.4.1 so I try this... Here's the thing:
4
1052
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 type". In practice, though, on nearly every machine that Python runs on, "char" is one byte, "short" is two bytes, and "int" is four bytes. "longs" and "long longs" tend to vary substantially, though; never assume sizes for them.
2
1155
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 module. my problem goes like this, ex.h ----------- #define NIL 0 /* Indicates ptr is nil */ #define NO_CODER 0 /* Means do not use an arithmetic
4
2907
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
10208
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.