# using the module ctypes you can access DLLs written in C/C++
# ctypes converts between Python types and C types
# there are two ways to write DLLs:
# most common uses cdecl, import with cdll
# Win and VB may use stdcall, import with windll
# module ctypes is built into Python25 and higher
# look under ctypes in the Python manual
from ctypes import *
# as an example let's use msvcrt.dll
# this is the MS C library containing many standard C functions
# import the C function strchr() from msvcrt.dll
strchr = cdll.msvcrt.strchr
# declare the return type ...
# a 'pointer to a string' (which then converts to a Python string)
strchr.restype = c_char_p
# these are the argument types ...
# Python string converts to 'pointer to a string' --> c_char_p
# Python single char string converts to C char --> c_char
strchr.argtypes = [c_char_p, c_char]
# now call the function and show the result
print strchr('abcdefg', 'd') # result --> defg
# some C functions are easier to access ...
printf = cdll.msvcrt.printf
printf("Hello, %s\n", "World!")
I am working creating a fully encapsulated, homogeneous singly linked data structure. The Listing class and SinglyLinkedList class that are part of the whole application compile fine, but the problem ...