![](/img/trans.png)
[英]Update values of a struct pointer in ctypes python without using a C function
[英]In Python using ctypes for passing pointer to struct pointer to C function
在 C 庫中有:
typedef struct A * B;
int create_b(B* b);
並使用 ctypes 我需要等效於的 Python:
B b;
create_b(&b)
struct A 在 Python 中實現為class A(ctypes.Structure)
。
所以,我試過:
b = ctypes.POINTER(A)
lib.create_b(ctypes.byref(b))
但它不起作用。 有很多類似的問題,但我試過的都沒有幫助。
這條線
b = ctypes.POINTER(A)
只是將b
設置為引用相同類型的ctypes.POINTER(A)
,其中真正想要的是用該類型構造的變量。 該行在末尾缺少括號:
b = ctypes.POINTER(A)()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.