从VB.NET将向量传递到C ++ [英] Passing vector to C++ from VB.NET

查看:112
本文介绍了从VB.NET将向量传递到C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我有一个用C ++编写的dll.它具有导出方法,该方法将字符串向量(std :: vector< std :: string xmlns:std =#unknown">)作为输入参数.我想从VB.NET代码中调用此方法.我是VB.NET的新手,所以我可能会错过一些与数据类型相关的基础知识.

我尝试使用List(Of String),但出现异常,说无法封送通用数据类型.

我可以为上述目的使用哪种数据类型?

Hi!

I have a dll written in C++. It has an exported method which takes a vector of strings (std::vector<std::string xmlns:std="#unknown">) as input parameter. I want to call this method from VB.NET code. I''m new to VB.NET, so I might have missed some basics related to the data types.

I tried using List(Of String), but I got an exception saying it is not possible to marshal generic data types.

Which data type(s) can I use for the purpose mentioned above?

推荐答案

这是完全可能的,但是需要一些仔细的工作.一个明显的解决方案是:在C ++方面,导出一个不同的函数,该函数应该包装原始的C ++函数.此函数应接受不同类型的参数:LPSTR或LPWSTR字符串的数组(而非向量).您可以使用标准的MarshalAs属性从.NET字符串中封送这些类型.新导出的C ++函数将使用这种类型的字符串来初始化std :: string的每个实例以及这些字符串的向量.另一种方法是编写自定义编组器.

—SA
This is quite possible, but needs some careful work. One obvious solution is this: on C++ side, export a different function which should wrap you original C++ function. This function should accept a different type of parameter: an array (not a vector) of LPSTR or LPWSTR strings. These types you can marshal from .NET strings using standard MarshalAs attributes. New exported C++ function would use strings of this type to initialize each instance of std::string and a vector of those strings. Another way could be writing custom marshaller.

—SA


我不是很积极,但我认为您不能直接做到这一点.取而代之的是,您将需要编写另一个C或C ++ DLL,该DLL接受来自VB.NET的字符串列表,然后该DLL将使用所有字符串构建std :: vector,然后调用原始DLL.那是我能想到的最好的. :)
I''m not positive, but I don''t think you can do this directly. Instead you will need to write another C or C++ DLL that accepts the list of strings from VB.NET and this DLL will then build the std::vector with all the strings and then call your original DLL. That''s the best that I can think of. :)


这篇关于从VB.NET将向量传递到C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆