返回值在c++里面为const char*,python 接收实际上为int类型
原因:python默认返回值为int
解决方法:
import ctypes
import os
CUR_PATH = os.path.dirname(__file__)
dllPath = os.path.join(CUR_PATH, "vando.dll")
pDll = ctypes.WinDLL(dllPath)
pResutl = pDll.get_term(1)
print(pResult)
改为:
import ctypes
import os
CUR_PATH = os.path.dirname(__file__)
dllPath = os.path.join(CUR_PATH, "vando.dll")
pDll = ctypes.WinDLL(dllPath)
pDll.get_term.restype = ctypes.c_uint64
print(pResult)
python 传入和返回dll的byte(在c++是char*)类型的中文输出乱码
原因:要解码
解决方法:
传入
pResutl = pDll.get_price(bytes("你", "gb2312"))
返回
b = ctypes.string_at(pResutl)
print(b.decode("gb2312"))
vscode 控制台输出中文乱码,但是cmd正常
在setting.json中添加
"code-runner.runInTerminal":true
记录 2020/3/26
n-N-n