2 回答

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)

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 和符號 ^
再次感謝
添加回答
舉報