from ctypes import c_int, CDLL, CFUNCTYPE import _ctypes_test dll = CDLL(_ctypes_test.__file__) def callback(value): return value testfunc_callback_i_if = dll._testfunc_callback_i_if testfunc_callback_i_if.restype = c_int testfunc_callback_i_if.argtypes = None MyCallback = CFUNCTYPE(c_int, c_int) testfunc_callback_i_if2 = dll._testfunc_callback_i_if testfunc_callback_i_if2.restype = c_int testfunc_callback_i_if2.argtypes = [c_int, MyCallback] cb1 = MyCallback(callback) def test_callbacks(): result = testfunc_callback_i_if(-10, cb1) if result != -18: raise Exception("bug1") cb2 = MyCallback(callback) result = testfunc_callback_i_if2(-10, cb2) if result != -18: raise Exception("bug2") test_callbacks()