[問題] 關於ctypes structure之使用
各位先進好,想請教各位一個問題;
小弟撰寫一個DLL檔, 結合其它函式庫,
包裹準備要在python中使用的函式,
然而在使用structure交換資料時出現了問題,
我想達到的目的是將結構傳入函式中處理,
由函式將值寫入結構的記憶體位置達到目的;
python:
-----------------------------------
#宣告結構struct
class point(Structure):
_fields_ = [("x", c_int),
("y", c_int)]
#宣告target由20個point組成
target = point*20
-----------------------------------
dll 實作函式:
-----------------------------------
DLLEXPORT void test_fuc(struct point *b)
{
b->x = 1;
b->y = 2;
}
----------------------------------
python呼叫:
-----------------------------------
from ctypes import *
class point(Structure):
_fields_ = [("x", c_int),
("y", c_int)]
x = cdll.LoadLibrary('dll_testing.dll')
x.test_fuc(pointer(target())) #我試過此種寫法但失敗
但無法實質存取內容
------------------------------------
若想要將target放入函式中, 請問該如何撰寫呢?
煩請先進給予指點了: ) 十分感謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.118.206.153
※ 編輯: takebreak 來自: 140.118.206.153 (08/02 16:54)
→
08/02 18:02, , 1F
08/02 18:02, 1F
→
08/02 18:03, , 2F
08/02 18:03, 2F
→
08/02 18:03, , 3F
08/02 18:03, 3F
→
08/02 23:36, , 4F
08/02 23:36, 4F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):