Solved

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

Posted on 2016-07-27
7
42 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 34

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 34

Expert Comment

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

-saige-
0
 
LVL 34

Expert Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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