Python Ctypes 双解引用指针

Python Ctypes Double De-reference Pointer

我在 DLL 中有一个 C 函数,看起来像这样。

ProcessAndsend(Format *out,      // IN
            char const *reqp,    // IN
            size_t reqLen,       // IN
            Bool *Status,        // OUT
            char const **reply,  // OUT
            size_t *resLen)      // OUT

调用成功后,一些内容会保存到所有 OUT 参数中。

使用 python ctypes(在 Windows 上)我想双重取消引用 **reply 指针并查看那里的值是什么。

感谢进阶

我没有你的 FormatBool 类型,所以通过一些替换,这里有一些示例 DLL 代码:

#include <stddef.h>
__declspec(dllexport) void ProcessAndsend(char *out,        // IN
                                          char const *reqp,   // IN
                                          size_t reqLen,      // IN
                                          int *Status,       // OUT
                                          char const **reply, // OUT
                                          size_t *resLen)     // OUT
{
    *Status = 1;
    *reply = "test";
    *resLen = 5;
}

这将检索输出数据。只需创建一些正确的 ctypes 类型的实例并通过引用传递它们:

>>> from ctypes import *
>>> dll = CDLL('your.dll')
>>> f = dll.ProcessAndsend
>>> f.argtypes = c_char_p,c_char_p,c_size_t,POINTER(c_int),POINTER(c_char_p),POINTER(c_size_t)
>>> f.restype = None
>>> status = c_int()
>>> reply = c_char_p()
>>> size = c_size_t()
>>> f('abc','def',3,byref(status),byref(reply),byref(size))
>>> status
c_long(1)
>>> reply
c_char_p('test')
>>> size
c_ulong(5L)