Passing a BSTR parameter to a COM method

Posted on 2003-03-03
Medium Priority
Last Modified: 2007-12-19
     I have to pass a BSTR string which is read from a xml file(using simple C-style fopen,fgetws methods)  to a COM method. Within the COM method this BSTR string is to be passed further to a method that takes _bstr_t as a parameter. The problem arises when the BSTR string is to be passed further to the method contained within the COM method. The conversion from BSTR to _bstr_t converts only a portion of the string and not the complete string. How do I solve this problem??

Thanks and Regards,
Question by:abhinarulkar
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

Assisted Solution

rainbowsix earned 60 total points
ID: 8062693
the conversion examples can be found at http://www.codeproject.com/com/binbstr.asp I guess you already have them and there is some other problem could you post the code segment plz.

also http://www.geocities.com/contactgirish/data.html


Expert Comment

ID: 8065102
How are you doing conversion?

Accepted Solution

may_f_24 earned 90 total points
ID: 8070996
I used a simple way:

the param is BSTR newVal
in the receiveing com method:
_bstr_t bstrVal

bstrVal = newVal;
SysFreeString (newVal);

from the calling method:
char szVal[20] = {"a string"};
BSTR newVal = SysAllocaString (A2W (szVal));
and then call the COM method
LVL 30

Expert Comment

ID: 9374636
No comment has been added lately (195 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: split points between may_f_24 &  rainbowsix

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --


EE Cleanup Volunteer

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

741 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