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;

tried but this error poped:
TypeError: list objects are unhashable

What does it try to tell me?

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??

No, just declare it. I'm suspecting you'll have a problem when you go to use it.

so, now; what is the cause of error:
TypeError: list objects are unhashable

what does the code look like now (you changed it but didn't repost it)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.