ctypes的應用筆記

2021-10-21 10:31:11 字數 1838 閱讀 8028

作用:c/c++與python混合程式設計的中間庫

官方文件:

c-type

cpython

c_bool

_bool

bool

c_char

char

1-character bytes object

c_wchar

wchar_t

1-character string

c_byte

char

intc_ubyte

unsigned char

intc_short

short

intc_ushort

unsigned short

intc_int

intint

c_uint

unsigned int

intc_long

long

intc_ulong

unsigned long

intc_longlong

__int64 or long long

intc_ulonglong

unsigned __int64 or unsigned long long

intc_size_t

size_t

intc_ssize_t

ssize_t or py_ssize_t

intc_float

float

float

c_double

double

float

c_longdouble

long double

float

c_char_p

char * (nul terminated)

bytes object or none

c_wchar_p

wchar_t * (nul terminated)

string or none

c_void_p

void *

int or none

pass

1、錯誤:oserror: [winerror 193] %1 不是有效的 win32 應用程式

因為生成的dll是32位,使用vs生成64位的就行了

2、互動指標

3、呼叫問題

4、.**件

5、__cdecl和__stdcall呼叫的問題

cpp中寫如下函式

char

*myadd

(int a[10]

,int b)

return

"ok"

;}

py中如下呼叫

test=windll.loadlibrary(

'test.dll'

)int10=c_int*

10a=int10(1,

2,3,

4,5,

6,7,

8,9,

10)b=c_int(2)

test.myadd.restype=pointer(c_char_p)

test.myadd.argtypes=

[pointer(int10)

,c_int]

#pointer定義該型別的指標

d=test.myadd(a,b)

print

(string_at(d,2)

)#從指定位址開始,返回指定字元長度的字串

print

(type

(a))

for i in a:

print

(i)

OpenCV應用筆記

1 使用cvsmooth函式,src與dst的depth要一致,否則會出現raiseexception錯誤。src和dst的位深不能為64位浮點。簡單模糊和高斯模糊支援 1 或 3 通道,8 位元 和 32 位元 浮點影象。這兩種方法可以 in place 方式處理影象。2 關於直接讀取iplima...

session應用筆記

session start 開始session會話處理 session只要用到這個,就必須開啟session start 放在檔案開頭 建立session,直接採用超級全域性變數賦值即可 session是存在伺服器端,一般存放1440秒,如果網頁沒有任何操作,會自動銷毀,當然,可以通過php.ini...

sed 應用筆記

sed 的筆記 sed 的替換指令 有兩款。分別如下 第一款 sed i s g 第二款,帶有 可以出現 在 的前面或者後面。sed i s g 假設 etc sysctl.conf檔案上,有如下的 指令。都替換為net.ipv4.tcp sack 0。net.ipv4.tcp sack 1 net...