Re: callback from C DLL returning an int [SEC=PERSONAL]

RayS <[email protected]> Fri, 15 Jul 2011 12:57:24 -0700
Newsgroups gmane.comp.python.ctypes
Message-ID <20110715195819.EYJC3919.fed1rmfepo101.cox.net@fed1rmimpo03.cox.net>
At 10:44 PM 7/14/2011, you wrote:

>If the callback genuinely is a C void function, then I'd have to say 
>that the library that calls it expects it to do something which your 
>code isn't doing - such as copying data out of a buffer and then 
>clearing the buffer - and the library code is subsequently blowing 
>up as a result of what ever needs doing having not been done (or 
>been signalled to have been done).  Do you have examples of 
>callbacks in other languages?
>
>Another possibility could be the calling convention used for the 
>callback function itself (as distinct from the convention used for 
>the function that sets the callback).  You really need the C++ 
>header file for the DLL to evaluate this (I'm assuming C++ based on 
>the snippets posted in your original message).


I just heard from the DLL author that (FUNCPTR) in the callback 
declaration is actually a macro for the following function typedef:
         typedef void (__stdcall *FUNCPTR)( int iStatus );

This is the c code:
         extern "C" void __declspec(dllexport) SetCallback( long lAddress )   {
             s_frontend.set_callback((FUNCPTR)lAddress );
         }

This is the .h declaration:
         extern "C" void __declspec(dllexport) SetCallback(long lAddress);

This is my Python call:
def py_data_ready_func(r):
     print "in py_data_ready_func 1", r

driver = ctypes.cdll.VBridge
CB_TYPE = ctypes.CFUNCTYPE(None, ctypes.c_int)
data_ready_ref = CB_TYPE(py_data_ready_func)
driver.SetCallback(data_ready_ref)

The FUNCPTR macro specifies __stdcall (?), but, if I use 
windll.VBridge to load the DLL none of the other methods will load - 
"ValueError: Procedure probably called with too many arguments (4 
bytes in excess)".
It is still beyond me where the issue lies, do they have a conflict 
in their declarations?

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