I'm learning ctypes right now and have made simple function and here is the code

#import ctypes module
import ctypes as ct
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.cdll.bass
#here is function description on the function
""" Loads a WAV, AIFF, MP3, MP2, MP1, OGG or plugin supported sample.
     HSAMPLE BASS_SampleLoad(
     BOOL mem,
         void *file,
         QWORD offset,
         DWORD length,
         DWORD max,
         DWORD flags
     );  
     
     CFUNCTYPE(restype, *argtypes)
     """
#The rguments list
res = bass_dll.BASS_SampleLoad.restype = [ct.c_int]        
args = bass_dll.BASS_SampleLoad.argtypes = [BOOL, ct.c_char_p, ct.c_int, ct.c_int, ct.c_int, ct.c_char_p]
prototype = ct.CFUNCTYPE(res, args)
print prototype

when I run I get error:
TypeError: restype must be a type, a callable, or None
I dont know what is wrong, so need help!

don't use a list when assigning restype: res = bass_dll.BASS_SampleLoad.restype = ct.c_int But I suspect you're in for a spot of trouble.

a FILE * is NOT a char * fname;

don't use a list when assigning restype: res = bass_dll.BASS_SampleLoad.restype = ct.c_int But I suspect you're in for a spot of trouble.

a FILE * is NOT a char * fname;

What do you mean?

the prototype called out void *file . I'm suspecting that it expects a C FILE * . A FILE * is a result of using the C library to open a file. You appear to be prototyping the argument that is void * file as a ct.c_char_p which I read to be a character pointer (as in a string.) The types are different.

so you say that when created, prototype calls the required arguments? I mean, I haven't passed any arg as you can see. I have just defined it. Should I pass all the arguments before call CFUNCTYPE??

This article has been dead for over six months. Start a new discussion instead.