第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python ctypes、dll 函數(shù)參數(shù)

Python ctypes、dll 函數(shù)參數(shù)

慕慕森 2021-11-16 09:57:07
我有一個帶有函數(shù)的 DLLEXPORT long Util_funct( char *intext, char *outtext, int *outlen )看起來它需要 char *intext、char *outtext、int *outlen。我試圖在 python 中定義不同的數(shù)據(jù)類型,所以我可以傳遞一個參數(shù),但到目前為止沒有成功。from ctypes import *string1 = "testrr"#b_string1 = string1.encode('utf-8')dll = WinDLL('util.dll')funct = dll.Util_functfunct.argtypes = [c_wchar_p,c_char_p, POINTER(c_int)]funct.restype = c_char_pp = c_int()buf = create_string_buffer(1024)retval = funct(string1, buf, byref(p))print(retval)輸出為 None,但我看到p. 你能幫我為函數(shù)定義正確的數(shù)據(jù)類型嗎?
查看完整描述

2 回答

?
GCT1015

TA貢獻(xiàn)1827條經(jīng)驗 獲得超4個贊

這應(yīng)該有效:


from ctypes import *


string1 = b'testrr'     # byte string for char*


dll = CDLL('util.dll')  # CDLL unless function declared __stdcall

funct = dll.Util_funct


funct.argtypes = c_char_p,c_char_p,POINTER(c_int) # c_char_p for char*

funct.restype = c_long # return value is long


p = c_int()

buf = create_string_buffer(1024) # assume this is big enough???

retval = funct(string1, buf, byref(p))


print(retval)


查看完整回答
反對 回復(fù) 2021-11-16
?
揚帆大魚

TA貢獻(xiàn)1799條經(jīng)驗 獲得超9個贊

感謝您的所有回答!我想我想通了。使用不是最聰明的方式,而只是嘗試/試驗不同的數(shù)據(jù)類型。由于這不是一個常見的圖書館,而且我沒有關(guān)于它的信息,也許 sulution 對其他人不會很有用,但無論如何。


看起來函數(shù)一次只處理一個字符,因為如果我傳遞一個單詞它只返回一個編碼字符。所以這里是:


from ctypes import *



buf = create_unicode_buffer(1024)

string1 = "a"

c_s = c_wchar_p(string1)


dll = CDLL('util.dll')

enc = dll.Util_funct


enc.argtypes = c_wchar_p, c_wchar_p, POINTER(c_int)


enc.restype = c_long # i don't think this type matters at all


p = c_int()



enc(c_s, buf, byref(p))



print(p.value)

print(buf.value)

輸出為 1 和符號 ^


再次感謝


查看完整回答
反對 回復(fù) 2021-11-16
  • 2 回答
  • 0 關(guān)注
  • 262 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號