-
October 24th, 2019, 04:21 AM
#1
Convert string to BSTR
I have a function
Code:
func(BSTR * path)
{
// From path paramter I use the path.
//Now I generate some lets say list of names separated by newline
string output = "Bob\n Rob \n Lilly \n";
// Now client wants the path to be modified with the output
SysFreeString(*path);
*path= SysAllocStringByteLen(output.c_str(), output.size());
}
Is the last two lines correct. Somehow testing doesnot seems ok !
-
October 24th, 2019, 04:41 AM
#2
Re: Convert string to BSTR
Could you use _bstr_t Class rather than the plain BSTR?
Then you would not care about SysFreeString/SysAllocString...
Victor Nijegorodov
-
October 24th, 2019, 04:45 AM
#3
Re: Convert string to BSTR
Thanks a lot Victor, but this is client interface and I cannot change
-
October 24th, 2019, 04:57 AM
#4
Re: Convert string to BSTR
can some windows experts help me with this please.
-
October 24th, 2019, 06:30 AM
#5
Re: Convert string to BSTR
Originally Posted by pdk5
Thanks a lot Victor, but this is client interface and I cannot change
Sure, the interface can't change but you can do what you like internally.
Code:
func(BSTR* path)
{
_bstr_t myPath(path);
// myPath has access to all of _bstr_t methods. happy, happy, happy
}
-
October 24th, 2019, 07:21 AM
#6
Re: Convert string to BSTR
Thanks I tried to convert the string into wstring. Then copied that back to parameter to be passed back to interface. This now worked.
May be I;ll try your suggestion also ..Thankyou again for commenting and giving inputs
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|