python調(diào)用C程序的結(jié)構(gòu)體和函數(shù)
來源:懂視網(wǎng)
責(zé)編:小采
時間:2020-11-27 14:27:41
python調(diào)用C程序的結(jié)構(gòu)體和函數(shù)
python調(diào)用C程序的結(jié)構(gòu)體和函數(shù):C代碼如下: #include <stdio.h> typedef struct TestDLL_ { int a; char *b; } testdll; testdll test(testdll t) { t.a=t.a+t.a; printf("%d\n%s\n",t.a,t.b); return t
導(dǎo)讀python調(diào)用C程序的結(jié)構(gòu)體和函數(shù):C代碼如下: #include <stdio.h> typedef struct TestDLL_ { int a; char *b; } testdll; testdll test(testdll t) { t.a=t.a+t.a; printf("%d\n%s\n",t.a,t.b); return t

C代碼如下:
#include <stdio.h>
typedef struct TestDLL_
{
int a;
char *b;
} testdll;
testdll test(testdll t)
{
t.a=t.a+t.a;
printf("%d\n%s\n",t.a,t.b);
return t;
}
python代碼如下:
from ctypes import *
#絕對路徑
dllpath='test.dll'
dll=CDLL(dllpath)
#python內(nèi)部參數(shù)賦值
a=c_int(125)
b=c_char_p('Hello world,Hello Chengdu')
#定義結(jié)構(gòu)體
class testdll(Structure):
_fields_=[('a',c_int),
('b',c_char_p)]
#實例化并賦值
t=testdll()
t.a=a
t.b=b
#設(shè)置返回值類型
dll.test.restype=testdll
#測試
t=dll.test(t)
print t.a
print t.b
x=raw_input('any key to continue')
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
python調(diào)用C程序的結(jié)構(gòu)體和函數(shù)
python調(diào)用C程序的結(jié)構(gòu)體和函數(shù):C代碼如下: #include <stdio.h> typedef struct TestDLL_ { int a; char *b; } testdll; testdll test(testdll t) { t.a=t.a+t.a; printf("%d\n%s\n",t.a,t.b); return t