Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Passing a BSTR parameter to a COM method

Posted on 2003-03-03
4
Medium Priority
?
569 Views
Last Modified: 2007-12-19
Hi,
     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,
Abhishek.
0
Comment
Question by:abhinarulkar
4 Comments
 
LVL 1

Assisted Solution

by:rainbowsix
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

0
 
LVL 1

Expert Comment

by:vadik
ID: 8065102
How are you doing conversion?
0
 
LVL 1

Accepted Solution

by:
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:
USES_CONVERSIONS;
char szVal[20] = {"a string"};
BSTR newVal = SysAllocaString (A2W (szVal));
...
and then call the COM method
0
 
LVL 30

Expert Comment

by:Axter
ID: 9374636
abhinarulkar,
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 ! --

Thanks,

Axter
EE Cleanup Volunteer
0

Featured Post

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!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

564 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