I'm trying to convert a wchar_t *
to BSTR
.
#include <iostream>
#include <atlstr.h>
using namespace std;
int main()
{
wchar_t* pwsz = L"foo";
BSTR bstr(pwsz);
cout << SysStringLen(bstr) << endl;
getchar();
}
This prints 0
, which is less than what I'd hoped. What is the correct way to do this conversion?
CString
doesn't wrap aBSTR
, although it has a method to allocate aBSTR
from aCString
(.AllocSysString()
).CString
doesn't help with automatic freeing of aBSTR
, though. – Jalbert