Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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?
Posted

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
 
Share this answer
 
v2
Comments
fjdiewornncalwe 3-Feb-11 21:40pm    
+5. Good answer.
Espen Harlinn 4-Feb-11 3:26am    
Sensible answer 5+
NeerajMD 9-Feb-11 5:05am    
Thanks!
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. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900