pythonPkg_ctypes

12 篇文章 0 订阅
8 篇文章 0 订阅
Python Standard Library >> Generic Operating System Services
  >> ctypes
     a foreign function library for Python

Reference>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  
  finding shared libraries<<<<<<<<<<<<<<<<<<<<<<<
    >> ctypes.util.find_library(name)
       return None|pathname
       Linux:find_library('m') => libm.so.*

  loading shared libraries<<<<<<<<<<<<<<<<<<<<<<<
    >> class ctypes.CDLL(name, mode=DEFAULT_MODE,handle=None,use_errno=False,use_last_error=False)
       return int
       using standard c calling convention
    >> class ctypes.OleDLL(name,mode=DEFAULT_MODE,handle=None,use_errno=False,use_last_error=False)
       return HRESULT
       Windows only
       using stdcall
    >> class ctypes.WinDLL(name,mode=DEFAULT_MODE,handle=None,use_errno=False,use_last_error=False)
       return int
       Windows only
       using stdcall
    >> class ctypes.PyDLL(name,mode=DEFAULT_MODE,handle=None)
       call Python C API functions
    >> ctypes.RTLD_GLOBAL
    >> ctypes.RTLD_LOCAL
    >> ctypes.DEFAULT_MODE
    >> PyDLL._handle
    >> PyDLL._name
    >> class ctypes.LibraryLoader(dlltype)
       dlltype=CDLL|PyDLL|WinDLL|OleDLL
    >> ctypes.cdll
    >> ctypes.windll
    >> ctypes.oledll
    >> ctypes.pydll
    >> ctypes.pythonapi

  foreign functions<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    >> class ctypes._FuncPtr
       base class for c callable foreign functions
      >> restype
         return int
      >> errcheck
         callable(result, func, arguments)
      >> exception ctypes.ArgumentError

  function prototypes<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    >> ctypes.CFUNCTYPE(restype,*argtypes,use_errno=False,use_last_error=False)
    >> ctypes.WINFUNCTYPE(restype,*argtypes,use_errno=False,use_last_error=False)
    >> ctypes.PYFUNCTYPE(restype,*argtypes)
       
    >> prototype(address)
       return func at address
    >> prototype(callable)
       create c callable func
    >> prototype(func_spec[,parameters])
       return shared lib func
       func_type = (name_or_ordinal, library)
    >> prototype(vtbl_index, name[, paramflags[, iid]]))
       return COM func
  
  utility functions<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    >> ctypes.addressof(obj)
       return int(obj address in memory)
    >> ctypes.alignment(obj_or_type)
       return alignment
    >> ctypes.byref(obj[, offset])
       return light-weight pointer to obj
    >> ctypes.case(obj, type)
       return new pointer to obj and with type type
    >> ctypes.create_string_buffer(init_or_size[,size])
       return c_char array
    >> ctypes.create_unicode_buffer(init_or_size[,size])
       return c_wchar array
    >> ctypes.DllCanUnloadNow()
       Windows only
    >> ctypes.DllGetClassObject()
       Windows only
    >> ctypes.util.find_library(name)
    >> ctypes.find_msvcrt()
    >> ctypes.FormatError([code])
    >> ctypes.GetLastError()
    >> ctypes.get_errno()
    >> ctypes.get_last_error()
    >> ctypes.memmove(dst, src, count)
    >> ctypes.memset(dst, c, count)
    >> ctypes.POINTER(type)
    >> ctypes.pointer(obj)
    >> ctypes.resize(obj, size)
    >> ctypes.set_conversion_mode(encoding, errors)
    >> ctypes.set_errno(value)
    >> ctypes.set_last_error(value)
    >> ctypes.sizeof(obj_or_type)
    >> ctypes.sizeof(obj_or_type)
    >> ctypes.string_at(address[,size])
    >> ctypes.WinError(code=None,descr=None)
    >> ctypes.wstring_at(address[,size])

  data types<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    >> class ctypesl._CData
      >> from_buffer(source[,offset])
      >> from_buffer_copy(source[,offset])
      >> from_address(address)
      >> from_param(obj)
      >> in_dll(library, name)
      >> _b_base_
      >> _b_needsfree_
      >> _objects

  fundamental data types<<<<<<<<<<<<<<<<<<<<<<<<<
    >> class ctypes._SimpleCData
      >> value
    >> class ctypes.c_byte
    >> class ctypes.c_char
    >> class ctypes.c_char_p
    >> class ctypes.c_double
    >> class ctypes.c_longdouble
    >> class ctypes.c_float
    >> class ctypes.c_int
    >> class ctypes.c_int8
    >> class ctypes.c_int16
    >> class ctypes.c_int32
    >> class ctypes.c_int64
    >> class ctypes.c_long
    >> class ctypes.c_longlong
    >> class ctypes.c_short
    >> class ctypes.c_size_t
    >> class ctypes.c_ssize_t
    >> class ctypes.c_ubyte
    >> class ctypes.c_uint
    >> class ctypes.c_uint8
    >> class ctypes.c_uint16
    >> class ctypes.c_uint32
    >> class ctypes.c_uint64
    >> class ctypes.c_ulong
    >> class ctypes.c_ulonglong
    >> class ctypes.c_ushort
    >> class ctypes.c_void_p
    >> class ctypes.c_wchar
    >> class ctypes.c_wchar_p
    >> class ctypes.c_bool
    >> class ctypes.HRESULT
    >> class ctypes.py_object
    >> class ctypes.wintypes

  structured data types<<<<<<<<<<<<<<<<<<<<<<<<<<
    >> class ctypes.Union(*args, **kw)
    >> class ctypes.BigEndianStructure(*args, **kw)
    >> class ctypes.LittleEdianStructure(*args, **kw)
    >> class ctypes.Structure(*args, **kw)
      >> _fields_
      >> _pack_
      >> _anonymous_

tutorial>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

  loading dynamic link libraries<<<<<<<<<<<<<<<<<
    >> cdll, load standard cdecl calling convention
    >> windll, Windows only, load stdcall calling convention
    >> oledll, Windows only, load stdcall calling convention, return HRESULT
    >> from ctypes import *
       Win:windll.kernel32, cdll.msvcrt
       Lin:cdll.LoadLibrary('libc.so.6'), CDLL('libc.so.6')

  accessing functions from loaded dlls<<<<<<<<<<<
    >> from ctypes import *
       <libc>.printf
       windll.kernel32.GetModuleHandleA
       cdll.kernel32[1]

  calling functions<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    >> <libc>.time(None)
    >> hex(windll.kernel32.GetModuleHandleA(None))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值