By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

python callbacks and windows

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
anybody?

Sep 11 '05 #2

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.