Ctype学习笔记

关于Ctype的学习笔记

官方文档

动态链接库

三种加载方式

  • cdll()
  • windll()
  • oledll()

在Max OX系统上的使用

偏偏书上没有mac系统的方法

1
from ctypes import *
2
libc = CDLL("libc.dylib")
3
# libc = cdll.LoadLibrary('libc.dylib')
4
# libc = cdll.LoadLibrary('/usr/lib/libc.dylib')

上述三种方式都可以

1
message_string = "Hello world!\n"
2
libc.printf("Testing: %s", message_string)
3
# 输出:
4
# H

没错! 只输出第一个letter! 只有在每个字符创前都加上b后才正常

1
message_string = b"Hello world!\n"
2
libc.printf(b"Testing: %s", message_string)

The small detail of the b prefix, which is a bytes literal, is the difference between passing an ASCII byte string b"Hello World!\n" versus a UTF-16LE encoded string

理解函数调用约定