1 Star 0 Fork 3

kentzhang/python-agent

forked from kentzhang/python-sdk 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
testcallback 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
kentzhang 提交于 2022-09-19 10:32 +08:00 . event test
import ctypes
import os
import platform
from ctypes import *
import time
FN_do_test = {}
FN_do_test["name"] = "do_test"
FN_do_test["argtypes"] = [ctypes.c_void_p]
FN_do_test["restype"] = []
read_lib_name = "D:\\code\\kent\\gitee\\python-sdk\\libtestcallback.dll"
nativelib = PyDLL(read_lib_name,ctypes.RTLD_GLOBAL)
print("native lib: ",nativelib)
nativelib.dotest.argtypes = [ctypes.c_void_p]
nativelib.dotest.restypes = []
platsys = platform.platform()
if platsys.lower().startswith("win"):
libc = cdll.msvcrt
##linux
if "linux" in platsys.lower():
cdll.LoadLibrary("libc.so.6")
def fn_callback(buffer,buffersize):
print("buffer:{},size:{}".format(buffer,buffersize))
#strbuffer = ctypes.string_at(buffer)
strbuffer :ctypes.c_char*10 = b''
strbuffer.from_buffer(buffer,0)
print("aaa",strbuffer)
libc.strncpy(buffer,b"abcdefg\0",5)
print("now buffer is ",ctypes.string_at(buffer))
l = libc.strlen(buffer)
return l
CFN_CALLBACK = CFUNCTYPE(ctypes.c_int,POINTER(ctypes.c_char_p),ctypes.c_int)
cb = CFN_CALLBACK(fn_callback)
print("cb:",cb)
nativelib.dotest(cb)
#while 1:
time.sleep(3)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/coderkent/python-agent.git
git@gitee.com:coderkent/python-agent.git
coderkent
python-agent
python-agent
master

搜索帮助