我是靠谱客的博主 羞涩煎蛋,最近开发中收集的这篇文章主要介绍Python 调用C++,返回char*,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 

C++代码

int Test(
const char*
input,
char**
output)
{
std::string str("From C++")
strcpy (*output,str.c_str());
output[str.size()] = '';
return 0;
}

Python代码

 


strtemp = c_char_p()
strtemp.value = b''
# 如果没有这一行,出现错误:
# OSError: exception: access violation writing 0x0000000000000000
print('111111')
print(strtemp)
print(byref(strtemp))
print('111111')
self.mydll.Test.restype = c_int
accnum = '123'
ret = self.mydll.Test(accnum.encode('utf-8'), byref(strtemp))
print('ret=', ret)
print('python strtemp=', strtemp.value.decode('utf-8'))

 

最后

以上就是羞涩煎蛋为你收集整理的Python 调用C++,返回char*的全部内容,希望文章能够帮你解决Python 调用C++,返回char*所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部