惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
G
Google Developers Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
F
Full Disclosure
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
C
Cisco Blogs
博客园 - 司徒正美
Project Zero
Project Zero
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
S
Securelist
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
T
Threatpost
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
S
Security Archives - TechRepublic
博客园 - Franky
N
News | PayPal Newsroom
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
A
Arctic Wolf
B
Blog

博客园 - Ady Lee

【C语言】二维数组在内存中的存储方式 C++:继承访问属性(public/protected/private) Makefile文件基本格式 异步IRP的教训(已附DUMP) IRQL 文件过滤驱动中的重入处理 FastIO 用poolmon来查找内存泄露 缓存管理器 浅议Windows 2000/XP Pagefile组织管理 FCB CCB FileObject WDM驱动改可手动加卸载的NT驱动 Windows 文件过滤驱动经验总结 PKCS #1 RSA Encryption Version 1.5 解决STM32 I2C接口死锁在BUSY状态的方法讨论 亲测实验,stm32待机模式和停机模式唤醒程序的区别,以及唤醒后程序入口 python中使用 C 类型的数组以及ctypes 的用法 Windbg 内核态调试用户态程序然后下断点正确触发方法(亲自实现发现有效) ___security_cookie机制,防止栈溢出 security cookie 机制(2)--- 初始化___security_cookie
python ctypes库3_如何传递并返回一个数组
Ady Lee · 2019-01-21 · via 博客园 - Ady Lee

可以将数组指针传递给dll,但无法返回数组指针,python中没有对应的数组指针类型。

如果需要返回数组,需借助结构体。

参考ctypes官方文档:

https://docs.python.org/3.6/library/ctypes.html#structures-and-unions

返回一个结构体例程:

# 返回结构体
import ctypes
path = r'E:\01_Lab\VisualStudioLab\cpp_dll\cpp_dll\Debug\cpp_dll.dll'
dll = ctypes.WinDLL(path)

class StructPointer(ctypes.Structure):
_fields_ = [("name", ctypes.c_char * 20),
("age", ctypes.c_int),
("arr", ctypes.c_int * 3)]

dll.test.restype = ctypes.POINTER(StructPointer)
p = dll.test()

print(p.contents.name)
print(p.contents.age)
print(p.contents.arr[0])
print(p.contents.arr[1])
print(p.contents.arr[2])

c++中

1、定义结构体

typedef struct StructPointerTest
{
char name[20];
int age;
int arr[3];
}StructPointerTest, *StructPointer;
2、定义函数

DLLEXPORT StructPointer __stdcall test() // 返回结构体指针
{
StructPointer p = (StructPointer)malloc(sizeof(StructPointerTest));
strcpy(p->name, "Joe");
p->age = 20;
p->arr[0] = 3;
p->arr[1] = 5;
p->arr[2] = 10;

return p;
}