1. 編碼問題:
遇到了幾個字符串轉換問題,總結如下:
# str to bytes str.encode(s)# bytes to str bytes.decode(b)
判斷編碼方式可用chardet模塊的chardet.detect(content)來協助。
2. char *有地址取內容:
strcontent = string_at(addr, -1)
3. 從動態鏈接庫中獲取函數并調用ctypes
from ctypes import *dll = CDLL("YourAPP.dll")dll.YourFunction()4. 從dll中調用c程序,返回char*的情況處理
本來在32位下用string_at就可以解決,但是換成64位后內存訪問出錯。所以改用restype,終于解決。
#32位可行,64位出錯:result = dll.function()result = string_at(result, -1)print(result)#后來改成用restype,32位/64位通用dll.function.restype = c_char_presult = dll.function()print(result)
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林站長站的支持。如果你想了解更多相關內容請查看下面相關鏈接
新聞熱點
疑難解答