According to the ctypes callback docs you can define python function
def my_callback(a, p, frame, p1, p2)
pass
and then create a pointer to a C callable function like this:
callback = write_callback_prototype(my_callback)
This function pointer can then be passed into FLAC
Answer from Ber on Stack OverflowAccording to the ctypes callback docs you can define python function
def my_callback(a, p, frame, p1, p2)
pass
and then create a pointer to a C callable function like this:
callback = write_callback_prototype(my_callback)
This function pointer can then be passed into FLAC
The problem that I have is the implementation. FLAC__Frame is never instantiated by the programmer, it's only called from from the initialization function, and the processing functions.I have to write the callback function myself, but he problem is that I don't know how I would do this, so if anyone knows how I should do this, then some help would be greatly appreciated.
In that case, just use:
import ctypes
class FLAC__Frame(ctypes.Structure):
pass
and pretend that it is already defined, and do not care because you only need pointer to it, which is basically position in memory.
I played with this awhile but since the way to instantiate a function with paramflags requires an exported function name and DLL in the syntax, it doesn't account for exported global function pointers.
Of course, you can get the same behavior with a little work by defining a wrapper to allocate and return the output parameter:
_four = function.in_dll( dll, 'four' )
def four(input):
output = ctypes.c_int()
_four(output,input)
return output.value
output = four(5)
print('output =',output)
"I am using Python 3.6.0 and ctypes to access functions exported from a .dll." I Think the problem is the following.
This
typedef void ( *function ) ( int *output, int input );
__declspec( dllexport ) extern const function four;
doesn't actually export a function from the dll, but only a pointer to a typedef'ed function, that is declared extern. In the end the Symbol Exporter has nothing really to work with. If you look for example in the generated lib after the build, you find a clean refenrence to two, but four is messed up.
If you declare the four function regulary
__declspec( dllexport ) const void four( int *output, int input );
and then define the function regulary
const void four( int *output, int input ) {
*output = 3 * input;
}
then you should be able to access four() and use paramflags.