callback from C DLL returning an int
RayS <[email protected]> Thu, 14 Jul 2011 16:20:51 -0700
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <20110714232119.ZIFY3912.fed1rmfepo102.cox.net@fed1rmimpo02.cox.net> |
My ctypes attempt is crashing the wxPython app.
This is how SetCallback is defined in the DLL:
extern "C" void __declspec(dllexport) SetCallback( long lAddress )
{
s_frontend.set_callback((FUNCPTR)lAddress );
}
//The function takes in a 32-bit long pointer to a function.
//The function when defined in a calling C program should take in one
parameter such as:
void ASLocalCode::call_back( int iMessage )
//This is fired when a new block of data is available. iMessage
integer value is always 6.
In Python I did this:
______________________________________
...
class myADC:
def __init__:
...
self.driver = cdll.dataDll
...
def data_ready_func(r):
print r
CB_TYPE = CFUNCTYPE(None, c_int)
self.data_ready_ref = CB_TYPE(data_ready_func)
print CB_TYPE, self.data_ready_ref
self.driver.SetCallback(self.data_ready_ref)
This prints:
data_ready_func 6
then XP pops up a notice "python.exe has encountered a problem" (the
app is still running!), then it all closes with the XP dialog "don't
send" button.
What is wrong here?
Ray
------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users