Solved

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

Posted on 2016-07-27
7
16 Views
Last Modified: 2016-08-22
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
0
Comment
Question by:festijazz
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:funwithdotnet
ID: 41732124
Try:
Dim Str as String = "something"
If you pass Nothing as a reference, your method might have trouble with it.
0
 
LVL 1

Author Comment

by:festijazz
ID: 41732431
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
0
 
LVL 32

Expert Comment

by:it_saige
ID: 41733132
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-
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Accepted Solution

by:
festijazz earned 500 total points (awarded by participants)
ID: 41733160
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
0
 
LVL 1

Author Comment

by:festijazz
ID: 41733164
This might be closed.
0
 
LVL 32

Expert Comment

by:it_saige
ID: 41733165
Glad you got it sorted out.

-saige-
0
 
LVL 32

Expert Comment

by:it_saige
ID: 41757599
Author solved the issue on their own.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now