Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-07-27
7
Medium Priority
?
48 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 35

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
festijazz earned 2000 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 35

Expert Comment

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

-saige-
0
 
LVL 35

Expert Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

885 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