python 3.6 导入c++dll所遇到的坑

1

返回值在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)

2

python 传入和返回dll的byte(在c++是char*)类型的中文输出乱码
原因:要解码
解决方法:
传入

pResutl = pDll.get_price(bytes("你", "gb2312"))

返回

b = ctypes.string_at(pResutl)
print(b.decode("gb2312"))

3

vscode 控制台输出中文乱码,但是cmd正常
setting.json中添加

"code-runner.runInTerminal":true

记录 2020/3/26
n-N-n

原文链接: https://www.cnblogs.com/Eritque-arcus/p/14253063.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    python 3.6 导入c++dll所遇到的坑

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/337894

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月1日 下午11:20
下一篇 2023年3月1日 下午11:20

相关推荐