使用函数
一般直接用就行了
windows下,如果构建动态库时导出的不是函数名,那么,使用
getattr(cdll.msvcrt,"??2@YAPAXI@Z")
winodws 下,导出函数不是用名字,而是用序号(ordinal)
cdll.kernel32[1]
windows 下,win32函数很多事A和W两个版本,必须明确指定
printf打印到真实的标准输出,而不是 sys.stdout (所以这些例子仅在控制台模式有效,而不是IDLE或PythonWin)
>>> printf=libc.printf
>>> printf("Hello, %s\n","World!")
Hello, World!
14
>>> printf("Hello, %S", u"World!")
Hello, World!
13
printf中,除字符串,整数外,其他要用 ctypes 类型,比如c_double(3.14)
printf("%f bottles of beer\n", 42.5)
不对
指定函数参数类型与返回值类型,比如调用c库中的sin函数
s = libc.sin
s.argtypes=[c_double]
s.restype=c_double
传递指针或引用
用byref>>>