python 调用so动态库函数时传char参数


import ctypes
from ctypes import *

ll = cdll.LoadLibrary
h_so = '/usr/lib/test.so'
lib = ll(h_so)
hid = ''.encode('utf-8')


lib.testfun.argtypes = [ctypes.c_char_p]
res = lib.testfun(hid)

printf = lib.printf
printf(hid)


so_hwid = c_char_p(hid).value.decode()

这套代码也能运行

lib = CDLL('/usr/lib/test.so')
p = create_string_buffer(1024)
res = lib.uoshwinfo_deviceh_get_hwid(p)
printf = lib.printf
printf(p)
posted @ 2022-07-29 16:20  Tarzen  阅读(260)  评论(0编辑  收藏  举报