Builtin functions ----------------- ``addressof(object)`` Returns the address of a ctypes instance as an integer. ``alignment(type_or_object)`` Returns the alignment requirements in bytes of a ctypes type or instance. ``byref(object)`` Returns a light-weight pointer to a ctypes instance. The returned object can only be used as function call parameter. Behaves the same as calling ``pointer(object)``, but is a lot faster. Same as ``&object`` in C. ``cast(object, typ)`` This function is similar to the cast operator in C. Returns a new instance of ``type`` which shares the memory block of ``object``. ``typ`` must be a pointer type. ``CFUNCTYPE(restype, *argtypes)`` Create a function prototype using the C calling convention. ``create_string_buffer(init, size=None)`` Convenience function to create a mutable character buffer. ``init`` must be a string. If ``size`` is supplied it must be a positive integer that specifies the size of the buffer, otherwise the length of the ``init`` string is used. This function returns a ctypes array of characters ``c_char``. ``create_unicode_buffer(init, size=None)`` Convenience function to create a mutable unicode buffer. ``init`` must be a unicode string. If ``size`` is supplied it must be a positive integer that specifies the number of characters in the buffer, otherwise the length of the ``init`` string is used. This function returns a ctypes array of characters ``c_wchar``. ``DllCanUnloadNow()``, ``DllGetClassObject(rclsid, riid, ppv)`` (Windows only) Functions used to implement COM servers. ``FormatError([code])`` (Windows only) Returns a textual description of the error code, or the last error code set by Windows. ``GetLastError()`` (Windows only) Returns the last error code set by Windows. ``memmove(dst, src, count)`` Same as the standard C ``memmove`` library function: copies ``count`` bytes from ``src`` to ``dst``. ``dst`` and ``src`` must be integers or anything else that can be converted into a pointer. ``memset(dst, c, count)`` Same as the standard C ``memset`` function. Fills the memory block at address ``dst`` with ``count`` bytes of value ``c``. ``dst`` must be an integer specifying an address, or a ctypes instance. ``pointer(object)`` This function creates a new pointer instance, pointing to the supplied argument which must be an instance of a ctypes type. The return pointer is of type ``POINTER(type(object))``. If you have a ctypes instance, and you want to pass the address of it to a function call, you should use ``byref(object)`` instead which is much faster. NULL pointer instances are boolean``False``, so to check for a NULL pointer do this:: # assuming ptr is in ctypes pointer instance if ptr: print "Non-NULL pointer instance" else: print "NULL pointer instance" ``POINTER(cls)`` This factory function creates and returns a new ctypes type. Pointer types are cached, so calling this function is cheap. To create a ``NULL`` pointer instance, call the created type without an argument:: null_ptr = POINTER(c_int)() ``set_conversion_mode(encoding, errors)`` This function sets the encoding/decoding rules which are used when ctypes has to convert between unicode and byte strings. It returns the previous encoding, as well as a tuple of any errors. If not set, default conversions are used: On Windows, ``msbc, ignore`` , on other systems, ``ascii, strict``. ``sizeof(type_or_object)`` Returns the size in bytes of a ctypes type or instance memory buffer. Does the same as the C sizeof() function. ``string_at(addr[, size])`` This function does the same as the Python ``PyString_FromString`` / ``PyString_FromStringAndSize`` C api functions. ``WinError(code=None, descr=None)`` XXX This is probably the worst named thing in ctypes! This function creates a ``WindowsError`` instance. If ``code`` is not specified, GetLastError() is called to determine the error code. If ``descr`` is not specified, ``FormatError`` is called to get a textual description of the error. ``WINFUNCTYPE(restype, *argtypes)`` (Windows only) Create a function prototype using the __stdcall calling convention (on Windows), or using the C calling convention (on Windows CE). ``wstring_at(addr[, size])`` This function does the same as the Python ``PyUnicode_FromWideString`` C api function. If ``size`` is not specified, ``wcslen`` is used to determine the string length. Deprecated functions -------------------- These deprecated functions are still supported for backwards comatibility, they should not be used for new code: ``c_buffer(init, size=None)`` Deprecated. Use ``create_string_buffer()`` instead. ``ARRAY(cls, len)`` Deprecated. Use ``cls * len`` instead. ``SetPointerType(pointer_class, cls)`` Deprecated.