BSTR supports Unicode
-
Hi , Is BSTR support UNICODE? I have a component method that takes BSTR as argument. That component is build with UNICODE support. In that method, I have written this code.
TCHAR tChar[255]; _stprintf(tChar,_T("%s"),(LPCTSTR)bstrName); // then print
Is it correct way ? Thanks in advance -
Hi , Is BSTR support UNICODE? I have a component method that takes BSTR as argument. That component is build with UNICODE support. In that method, I have written this code.
TCHAR tChar[255]; _stprintf(tChar,_T("%s"),(LPCTSTR)bstrName); // then print
Is it correct way ? Thanks in advanceA
BSTR
is a Unicode string (but beware: a Unicode string is ***NOT*** a BSTR). No conversion like your doing may be needed.Steve
-
Hi , Is BSTR support UNICODE? I have a component method that takes BSTR as argument. That component is build with UNICODE support. In that method, I have written this code.
TCHAR tChar[255]; _stprintf(tChar,_T("%s"),(LPCTSTR)bstrName); // then print
Is it correct way ? Thanks in advance -
Hello, i delete my post because is not correct!!! Take a look at next post from Stephen Hewitt Regards termal -- modified at 9:44 Tuesday 3rd April, 2007
termal wrote:
BSTR bstr = _T("text");
This is a serious coding error. For a start a
BSTR
is length prefixed. This means that the length of theBSTR
is stored before the pointer. Your string is not. SecondlyBSTR
s are always Unicode; useL"your string"
not_T
. Finally, in most instances, a specific allocater is assumed. Your code should look like this:BSTR bstr = SysAllocString(L"text");
To free the string use
SysFreeString
. No offence, but this is basic COM; I recommend doing some serious reading as creating software lacking these fundamentals will end in tearsSteve
-
termal wrote:
BSTR bstr = _T("text");
This is a serious coding error. For a start a
BSTR
is length prefixed. This means that the length of theBSTR
is stored before the pointer. Your string is not. SecondlyBSTR
s are always Unicode; useL"your string"
not_T
. Finally, in most instances, a specific allocater is assumed. Your code should look like this:BSTR bstr = SysAllocString(L"text");
To free the string use
SysFreeString
. No offence, but this is basic COM; I recommend doing some serious reading as creating software lacking these fundamentals will end in tearsSteve
-
There are classes such as ATL's
CComBSTR
and_bstr_t
(not part of ATL) which make working withBSTR
s easier and safer.Steve
-
Hi , Is BSTR support UNICODE? I have a component method that takes BSTR as argument. That component is build with UNICODE support. In that method, I have written this code.
TCHAR tChar[255]; _stprintf(tChar,_T("%s"),(LPCTSTR)bstrName); // then print
Is it correct way ? Thanks in advanceI know I'm being a bit anal, but if you are going to _T and TCHAR, then you need to write you app to build in both ANSI and UNICODE. Your code gives the impression that it might build in ANSI but it in fact will not work. To make your code work in both ansi and UNICODE TCHAR tChar[255]; _stprintf(tChar,_T("%ls"),(LPCWSTR)bstrName); // then print
Tim Smith I'm going to patent thought. I have yet to see any prior art.