Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BSTR, wchar_t and Character Arrays

Status
Not open for further replies.

MoonchildHK

Programmer
Jun 5, 2001
22
HK
Hi again,

I have a line of code from an example program like this:

Code:
CComBSTR bstrFileName( L"c:\\Test.avi" );

I want to replace the text with a string variable read from a text file. So I have something like...

Code:
char *FileName;
.
.
.
CComBSTR bstrFileName( charFileName );

But that doesn't seem to work :-( Does anyone have any idea how I can do this? I have look at websites that talk about converting char * to BSTR but it looks horribly complicated.. is there an easy way?

Thanks,

Moonchild
 
When I look into the helpfile I see that BSTR is only an alias for wchar*
So to convert a char* to BSTR, it is very simple :


char filename[10];
BSTR bFilename= (BSTR) filename;

the pointer bFilename points now to the string filename

Wim Vanherp
Wim.Vanherp@myself.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top