Send VB.Net string to VC ++

pts.
Tags:
Development
I am porting a VBA app to VB.Net. The VBA app uses structures, to send data, including strings, to a VC++ dll. When doing this via VB.Net, gibberish is passed to the VC++ dll. I suspect it is because strings are data types in VBA, but are objects (with lots of methods etc.) in VB.Net. So...does anyone know how to send a VBA (or VB 6) string data type, from within VB.Net, without making it into a full-blown String object? Thanks, P. Panke

Answer Wiki

Thanks. We'll let you know when a new response is added.

In the past in VB6 I’ve done it like this:

dim myStr as string * 10

This makes it a fixed length, null terminited char array that can be passed to c++. The problem is checking for buffer overflows on the c++ side.

If you can, I’d suggest using VB.NET classes and wrapping it with ActiveX. Using ActiveX in c++ should be fairly simple. Better yet, if you can convert the VC++ dll to .NET (managed code using .NET framework classes) you can skip the ActiveX part.

Otherwise, you can still compile C++ in .NET (unmanaged code and no .NET framework) and keep all your develpment in the same version of Visual Studio. Depending on what you’ve got in the c++ part we’ve had good luck doing this. The problem is that a string class in .NET framework and unmanaged code are 2 different animals and you cant pass them back and forth without a COM wrapper.

Good luck

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following