python dll 指针_将指针从C++ DLL返回到Python的指针返回

博主成功地从C++ DLL将指向myStruct结构的指针传递到Python,现在遇到问题在于如何返回指向myStruct结构体指针向量的指针。在C++中创建并返回了myVector指针,但在Python端尝试解析时遇到错误,导致打印的内容无效,引发了UnicodeEncodeError。
摘要由CSDN通过智能技术生成

我已经成功地将指向struct(包含wchar_t*)的指针从c++dll返回到Python中,如下所示:

C++代码:...

typedef struct myStruct{

wchar_t* id;

wchar_t* content;

wchar_t* message;

} myStruct;

DLLAPI myStruct* DLLApiGetStruct(){

myStruct* testStruct = new myStruct();

testStruct->id = _T("some id");

testStruct->content = _T("some content");

testStruct->message = _T("some message");

return testStruct;

}

Python代码:

^{pr2}$

好的,这很好,问题是现在我需要返回指向这些结构的指针向量上的指针。我试过了:

C++代码:typedef std::vector myVector;

...

DLLAPI myVector* DLLApiGetVector(){

myVector* testVektor = new myVector();

for(i=0; i< 5; i++){

myStruct* testStruct = new myStruct();

testStruct->id = _T("some id");

testStruct->content = _T("some content");

testStruct->message = _T("some message");

testVektor->push_back(testStruct);

}

return testVektor;// all values in it are valid

}

Python代码:

我认为第一行和第二行是不正确的(这是重新键入的正确方法吗?):vectorOfPointersType = (POINTER(DeltaDataStruct) * 5) #5 is number of structures in vector

myDLL.DLLApiGetVector.restype = POINTER(vectorOfPointersType)

vectorOfPointersOnMyStruct= myDLL.DLLApiGetVector.contents

for pointerOnMyStruct in vectorOfPointersOnMyStruct:

result = pointerOnMyStruct.contents

print result.id, result.content, result.message

最后一行中的值无效-我猜是内存中的一些随机部分。

这是我得到的错误:UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-11: character maps to

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值