473,386 Members | 1,886 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,386 software developers and data experts.

python callbacks and windows

I was wondering if anyone could point me to an example. Currently i
have a c++ program which calls and c++ dll (i created both). The dll
uses SendMessage to pass messages back to the calling .exe, and the
..exe process the messages in it's Windows Procedure function
WindProc().

What i want is to receive these messages ( the contents of each message
will be plain text), in python using a callback (i think this is what i
need).

I don't know whether (or if it's possible) to implement the windows
procedure and stuff in python, eliminating the need for the .exe
altogether.

or should i do it the other way, to add a callback function in python,
and for the windows procedure in the .exe to call this python callback?

in any case, some simple code examples would be great.

cheers.

Sep 9 '05 #1
4 1901
anybody?

Sep 11 '05 #2
On 9 Sep 2005 03:20:09 -0700, da**********@gmail.com wrote:
I was wondering if anyone could point me to an example. Currently i
have a c++ program which calls and c++ dll (i created both). The dll
uses SendMessage to pass messages back to the calling .exe, and the
.exe process the messages in it's Windows Procedure function
WindProc().
This sounds like your main program is ordinary C++ GUI and the dll could
be anything, but you probably cause it to be loaded and initialized at
least from the GUI main prog, maybe just by automatic dependency loading.
It is not clear whether you have a lot of code and would like to use python
for some aspect of processing special messages, or whether you have a tentative
start in C++ for an application you'd rather develop entirely in python.
What you want to do next will probably depend on what you have.
What i want is to receive these messages ( the contents of each message
will be plain text), in python using a callback (i think this is what i
need). I would guess that if you want to use windows messages, it might be easiest
to receive them in the main message loop and to recognize the special messages
there (vs all the standard windows stuff) and at that point call from C++ to
python to process the plain text contents. The question is what do you want to
get back, and what side effects and state-ful processing might you want to do,
and if there is state, do you want to maintain it in python or C++, and how
to you want to access from the other side if you need to.

Calling from C++ to python and vice versa is discussed in the docs re extensions
and embedding etc. (See http://python.org/doc/ links to "Extending and Embedding"
and "Python/C API")
I don't know whether (or if it's possible) to implement the windows
procedure and stuff in python, eliminating the need for the .exe
altogether. Have you looked at tkinter? It will let you make a GUI that runs under windows,
and then you can code in python.
or should i do it the other way, to add a callback function in python,
and for the windows procedure in the .exe to call this python callback?

in any case, some simple code examples would be great.

I would suggest downloading the python sources zip or tgz in addition
to the standard installation (which presumably you already have). The
reason is that the sources contain a demo subdirectory with useful examples
of what can be done with tkinter (and other stuff as well). Some of it
could stand to be updated to take advantage of current python, but you
can run the demo examples and modify them to learn a lot about what can be done.

<aside to python maintainers>
BTW, does python.org have a directory tree somewhere with a duplicate of a source installation
that people could browse with ftp:// ? That way, people could get access to the
demos and other sources without having to download the whole thing,
(e.g., ftp://python.org/pub/python/2.4.1/Python-2.4.1.tgz is ~9mb)
and people could also post with url references to particular sources.
Seems like providing source trees could be automated, so there would
only be an initial effort involved.
</aside>

Regards,
Bengt Richter
Sep 11 '05 #3
da**********@gmail.com wrote:
I was wondering if anyone could point me to an example. Currently i
have a c++ program which calls and c++ dll (i created both). The dll
uses SendMessage to pass messages back to the calling .exe, and the
.exe process the messages in it's Windows Procedure function
WindProc().

What i want is to receive these messages ( the contents of each message
will be plain text), in python using a callback (i think this is what i
need).

I don't know whether (or if it's possible) to implement the windows
procedure and stuff in python, eliminating the need for the .exe
altogether.

or should i do it the other way, to add a callback function in python,
and for the windows procedure in the .exe to call this python callback?

in any case, some simple code examples would be great.

cheers.

What you ask for is somewhat hard to find easy answers for. But here is
something that might help:

1. Example of Python function to a C library as a callback:
http://groups.google.com/group/comp....8eeeffba9fa14b
2. Venster, a highly native Windows GUI toolkit for Python based on the
ctypes ffi library:
http://venster.sourceforge.net/htdocs/index.html

Khalid

Sep 12 '05 #4
cheers for the replies.

so far using ctypes, i have managed to load a dll, and have the dll
call a function in my python code using function pointers.

what i now need to do is load an .exe that contains a windows procedure
(window is hidden).

how can i load an .exe using python like i loaded the dll.

will winmain be executed?

Sep 12 '05 #5

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

Similar topics

76
by: Nick Coghlan | last post by:
GvR has commented that he want to get rid of the lambda keyword for Python 3.0. Getting rid of lambda seems like a worthy goal, but I'd prefer to see it dropped in favour of a different syntax,...
4
by: Randall Hopper | last post by:
What is the correct way to propagate exceptions from Python callbacks? When I do this: Python -> C++ -> Python Callback (example attached) an exception raised in the callback doesn't make it...
8
by: Saravanan | last post by:
Hello, Im running Python Application as a Windows Service (using windows extensions). But, sporadically the application crashes (crash in Python23.dll) and this stops the service. This problem...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
0
by: Frank Niessink | last post by:
Hi, I'm trying to get an application working with Python 2.5 that works fine with Python 2.4. This issue occurs both on Windows XP as well as on Mac OSX. Some context: I use the...
0
by: mg | last post by:
When make gets to the _ctypes section, I am getting the following in my output: building '_ctypes' extension creating build/temp.solaris-2.10-i86pc-2.5/home/ecuser/Python-2.5.1/ Modules/_ctypes...
3
by: Siegfried Heintze | last post by:
I need to understand some User32.dll functions and I'm making an elaborate GUI so I can easily experiment with different parameters. This is taking a long time. I'm new to python and I'm thinking...
4
by: Sayanan Sivaraman | last post by:
Hey all, So I've written a simple video player using directshow/COM in VC++, and I'm in the process of translating it to python. For example, when the avi starts playing, I have a call...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.