[Help] Cannot retrieve a bstr* via com interface into a system.string in vb.net

festijazz
festijazz used Ask the Experts™
on
Hello Everyone,

I am getting the following issue:
Cannot retrieve a bstr* via com interface into a system.string in vb.net

I tryed to use StringBuilder but then I get a compilation error.
I also did:  

Dim Str as String = nothing

myobj.getMessage(Str)
--> result: nothing

Is there an equivalent like in c# using [ref] - > myobj.getMessage(ref Str);  where this works as expected.

All inputs are welcome.
Thank you very much in advance.
Best regards
MiQi
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try:
Dim Str as String = "something"
If you pass Nothing as a reference, your method might have trouble with it.

Author

Commented:
Hello,
this solution does not work, I get something back as result. This does not modify the string.

please help.
thank you.
Best regards.
MiQi

Commented:
But you are not getting the string itself, rather you are getting the pointer.  You need to retrieve the string value from the memory location that the pointer references.  For that, .NET has some ready made helper methods in the System.Runtime.InteropServices namespace.  The one that is of benefit to you is Marshal.PtrToStringBSTR(IntPtr).

-saige-
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Hello,
Thank you for your comment, I just found the issue.  It was not possible as like vb6 it won't work the same way.  It was related to the odl definition.  The parameter was only set [in] but should be [in, out].  Now it works nicely.

Thank you for your inputs but it related to the unmanaged code.
Hopefully not a big change to cover it.
Best regards.
MiQi

Author

Commented:
This might be closed.

Commented:
Glad you got it sorted out.

-saige-

Commented:
Author solved the issue on their own.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial