[python-win32] Ant: RE: Problems with Implementing Callback Python/C++-DLL

Oleg Novychny oleg_python at yahoo.de
Thu Aug 4 17:41:45 CEST 2005


--- Mark Hammond <mhammond at skippinet.com.au> schrieb:

> > So I’m not sure how can I “register”
> my_set_callback function in the
> already
> > started Python-Interpreter and to “explain” my DLL
> which Python-Function
> is
> > to call when the new values in my DLL were
> calculated.
> 
> I'm not sure I understand your problem.  The tail of
> the code you posted
> looks like a standard Python module - although you
> did not show the "module
> init" code.  Assuming this was a normal module,
> Python code would be able to
> say:
> 
> import foo
> foo.callback(some_func)
> 
> Which is how my_set_callback will be called. 
> However, if you have no module
> init code, there will be no entry point to the
> function.  How is your DLL
> loaded by Python (or is it your DLL that loads
> Python?).
> 
> Mark

It is Python that loads my DLL. For that purpose I
implemented this SoundProcLib-Class in Python:

from ctypes import*
import sys

class SoundProcLib(object):
    def __init__(self, library):
        self.library = library

        @cdecl(c_int, library, [c_int, c_int, c_int,
c_int, c_int, c_ulong])
        def StartProcessing(f1, f2, f3, f4, f5, ul1): 
        
            if 0 == StartProcessing._api_(f1, f2, f3,
f4, f5, ul1):
                raise WinError()
            return None
        self.StartProcessing = StartProcessing

        @cdecl(c_int, library, [POINTER(c_ulong),
POINTER(c_double), POINTER(c_int), POINTER(c_int),
POINTER(c_double), POINTER(c_int)])
        def GetResults():
            ulHz,dNoise,bAudio,bCrackFlag,dSNR,bBeep =
c_ulong(), c_double(), c_int(), c_int(), c_double(),
c_int()
            if 0 ==
GetResults._api_(byref(ulHz),byref(dNoise),byref(bAudio),byref(bCrackFlag),byref(dSNR),byref(bBeep)):
                raise WinError()
            return
ulHz.value,dNoise.value,bAudio.value,bCrackFlag.value,dSNR.value,bBeep.value
        self.GetResults = GetResults

        @cdecl(c_int, library, [c_void_p])
        def EndProcessing():
            if 0 == EndProcessing._api_(None):
                raise WinError()
            return None
        self.EndProcessing = EndProcessing


So my steps are:
1. I'm calling my DLL with StartProcessing() -
function from this class.
2. I read the values out of my DLL with GetResults()

 It works without problems. The only thing is: I'm
just not sure what is the right way to implement my
wish: Calling my Python function GetResults() from
inside of my DLL, when a certain event in my DLL is
happend.

Thanks a lot
Oleg


	
		
___________________________________________________________ 
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de


More information about the Python-win32 mailing list