鬼上身跳不过门槛

鬼上身跳不过门槛

类型对比表

  • char 与 wchar 之间,一个是C类型单字节的编码,一个是 Unicode 两个字节的编码,通常这两个之间可以通过decode和encode的方式进行相互之间转换。
  1. 普通类型赋值

    普通类型赋值

    	from ctypes import *
    	a = c_int(2)
    	print(type(a))
    	a = 2
    	print(type(a))
    	a = c_int(2)
    	a.value = 3
    	print(a)
    	"""
    	<class 'ctypes.c_long'>
    	<class 'int'>
    	c_long(3)
    	[Finished in 0.1s]
    	"""
    

    非匹配类型赋值

  2. 字符串创建

    • C风格字符串
      	from ctypes import *
      	buf = create_string_buffer(10)
      	print(sizeof(buf),buf,type(buf),buf.raw,buf.value)
      	buf = create_string_buffer(b"test",10)
      	print(sizeof(buf),buf,type(buf),buf.raw,buf.value)
      	buf = create_string_buffer(b"test")
      	print(sizeof(buf),buf,type(buf),buf.raw,buf.value)
      	"""
      	10 <ctypes.c_char_Array_10 object at 0x037A9460> <class 'ctypes.c_char_Array_10'> b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' b''
      	10 <ctypes.c_char_Array_10 object at 0x03835100> <class 'ctypes.c_char_Array_10'> b'test\x00\x00\x00\x00\x00\x00' b'test'
      	5 <ctypes.c_char_Array_5 object at 0x037A9460> <class 'ctypes.c_char_Array_5'> b'test\x00' b'test'
      	[Finished in 0.1s]
      	"""
      
    • Unicdoe风格
      	from ctypes import *
      	buf = create_unicode_buffer(10)
      	print(sizeof(buf),buf,type(buf),buf.value)
      	buf = create_unicode_buffer("test",10)
      	print(sizeof(buf),buf,type(buf),buf.value)
      	buf = create_unicode_buffer("test")
      	print(sizeof(buf),buf,type(buf),buf.value)
      	"""
      	20 <ctypes.c_wchar_Array_10 object at 0x00AB94F0> <class 'ctypes.c_wchar_Array_10'>
      	20 <ctypes.c_wchar_Array_10 object at 0x02B15100> <class 'ctypes.c_wchar_Array_10'> test
      	10 <ctypes.c_wchar_Array_5 object at 0x00AB94F0> <class 'ctypes.c_wchar_Array_5'> test
      	[Finished in 0.1s]
      	"""
      
  3. 可以通用的类型。

  4. 自定义类型作为参数。

11-24 04:37