|
-
June 29th, 1999, 08:21 AM
#1
Converting Strings
Hi,
I'm having a problem concerning the conversion of strings.
I need to convert a char* to a BSTR. I can't get this working correctly.
can somebody please help me?
Kind regards
Ruben van Straten
-
June 29th, 1999, 11:02 AM
#2
Re: Converting Strings
Try Using,
int iwstrLen = (strlen(szAnsiString) + 1) * 2;
WCHAR* pwString = new WCHAR[iwstrLen];
MultiByteToWideChar(CP_ACP, NULL,
szAnsiString, -1,
pwString, iwstrLen,
NULL, NULL);
BSTR bstrString = SysAllocString(pwString);
delete []pwString;
You can find more information and examples by searching MSDN for :
MutliByteToWideChar
or
WideCharToMultiByte
-Erik
-
June 29th, 1999, 11:07 AM
#3
Re: Converting Strings
there is a macro defined
T2OLE
which takes a char* as its parameter and returns a BSTR, something like:
USES_CONVERSION; // defines some stuff that T2OLE needs
char* pString = "Some string";
BSTR bstrString = T2OLE(pString);
HTH
--michael
-
June 29th, 1999, 11:41 AM
#4
Re: Converting Strings
You're code is wrong there. When you calculate the size of the string you don't have to multiply it by 2. The new operator can figure out the size, so therefore you don't have to account that WCHAR is 2 times as large
-
June 29th, 1999, 12:58 PM
#5
Re: Converting Strings
Yes. I realize that now. I should have had a can of Coke before I started replying to messages this morning. Over all it still works. It just has extra memory allocated that is not being used or needed for a short time.
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
|