python callbacks and windows

D

davidstummer

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.
 
B

Bengt Richter

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
 
A

A.B., Khalid

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...+as+a+callback"&rnum=1&hl=en#6c8eeeffba9fa14b
2. Venster, a highly native Windows GUI toolkit for Python based on the
ctypes ffi library:
http://venster.sourceforge.net/htdocs/index.html



Khalid
 
D

davidstummer

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top