python3利用ctypes传入一个字符串类型的列表方法
作者:abc15766228491 时间:2021-06-10 20:33:36
c语言里:c_p.c
#include <stdio.h>
void get_str_list(int n, char *b[2])
{
printf("in c start");
for(int i=0;i<n;i++)
{
printf("%s", *(b+i));
printf("\n");
}
printf("in c end");
}
编译为动态库的命令:
gcc -o hello1.so -shared -fPIC c_p.c
python里:p_c.py
from ctypes import *
ll = cdll.LoadLibrary
lib = ll("./12_23_ctype_list/hello1.so")
n = 3
str1 = c_char_p(bytes("nihao", 'utf-8'))
str2 = c_char_p(bytes("shijie", 'utf-8'))
a = (c_char_p*2)(str1, str2)
lib.get_str_list(2, a)
输出
in c startnihao
shijie
in c end
来源:https://blog.csdn.net/abc15766228491/article/details/78882605
标签:python3,ctypes,字符串
0
投稿
猜你喜欢
Php获取金书网的书名的实现代码
2023-07-14 02:31:21
ASP.NET Core优雅的在开发环境保存机密(User Secrets)
2023-07-15 20:25:37
装了 Access 2003 安全更新 (KB981716) 之后 Access 打不开
2010-12-09 19:59:00
python的random和time模块详解
2023-07-27 18:16:27
Python之根据输入参数计算结果案例讲解
2022-08-27 07:44:50
小议sqlserver数据库主键选取策略
2011-10-24 19:51:30
13个超酷的js显示时间效果
2007-08-30 09:52:00
Python 合并拼接字符串的方法
2022-05-26 08:58:08
如何对PHP程序中的常见漏洞进行攻击(下)
2023-11-16 14:50:19
sqlserver数据库迁移后,孤立账号解决办法
2011-10-24 20:01:40
PHP的PDO预定义常量讲解
2023-06-09 13:35:54
简单了解Python读取大文件代码实例
2022-10-23 11:46:19
python difflib模块示例讲解
2022-01-21 04:35:57
asp_数据库操作封装
2010-04-03 21:00:00
QQ聊天窗口链接提示效果代码
2008-12-16 12:59:00
技巧和诀窍:用Silverlight支持全屏模式
2007-09-23 12:37:00
详解python中的defaultdict 默认值
2022-12-27 08:51:40
Python 不设计 do-while 循环结构的理由
2021-08-04 11:55:19
关于pycharm python3.7成功安装dlib库的问题
2022-03-04 04:22:45
在asp中使用js的encodeURIComponent方法
2012-11-30 20:05:53