Since Python Win32 lib does not implement DDE Advise Loop and i need it
for a project, i guessed that Boost Python would be a way to integrate
the ddeml lib with my python code. I guessed i could just call
call_method inside the DDE Callback function, but when i do that python
crashes. I can't(or couldnt find how to) add the DDE Callback function
to the Python Module and i tried through a 2 stages call(DdeCallback
calls a Python Module function that call_method) without success.
Everything else works great... I can connect to the DDE Server, the
advise loop works, my setPyCallback/getPyCallback works... I just can't
get any python to work on the C++ DDECallback function.<br>
<br>Here is part of the code<br>------------------<br><br>PyObject* myPythonCallback;<br>void CallPy(TCHAR SomeValue){<br> boost::python::call<void>(<div id=":193" class="ii gt">myPythonCallback,SomeValue);<br>}<br>
HDDEDATA CALLBACK DdeCallback(UINT wType,UINT uFmt,HCONV hconv,HSZ hsz1,HSZ hsz2,HDDEDATA hData,DWORD dwData1,DWORD dwData2){<br>
..........<br> switch (wType) {<br> case XTYP_ADVDATA:<br> .................. bunch of code ..........<br> CallPy(mybuffer);<br> return((HDDEDATA)DDE_FACK);<br>
}<br>int ddeConnect();<br><br>void ddeAdvise(TCHAR* topic);<br><br>void setCallback(PyObject* p){<br> boost::python::call<void>(p,"3");// test calling function and WORKS<br> myPythonCallback = p;<br>
}<br><br>BOOST_PYTHON_MODULE(extending)<br>
{<br> using namespace boost::python;<br> def("ddeConnect", ddeConnect);<br> def("ddeAdvise", ddeAdvise);<br> def("ddeSetCallback", setCallback);<br> def("CallPy", CallPy);<br>
}<br><br>-------------<br><br>Python<br>------------<br>import extending<br>import wx<br>import justAFrame<br><br>def mCB (valor):<br> print "mCB",str(valor)<br> return float(str(valor))<br><br>class MyFrame(justAFrame.MyFrame):<br>
def initAfter (self):<br> justAFrame.MyFrame.initAfter(self)<br> extending.ddeConnect()<br> extending.ddeSetCallback(mCB)<br> extending.CallPy("1") #WORKS<br>
extending.ddeAdvise("0012PETR4;1")<br><br>app = wx.PySimpleApp()<br>frame=MyFrame(None,title="DDE Test")<br>app.MainLoop()<br>--------------<br><br><br>How
can i make this DdeCallback to interact with a python function defined
by the user ? Is there a better way to do this ? I'm open to
suggestions.</div>