Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::string to LPOLESTR

Tags:

c++

string

com

ole

I have an array of strings like this:

using std::string;
string myArray[] = { string("abc"), string("foo"), string("muh") };

Now I want to use this function:

HRESULT Init(T* begin, T* end, IUnknown* pUnk, CComEnumFlags flags = AtlFlagNoCopy );

T is in my case LPOLESTR. So I need to convert the array of std::string to LPOLESTR respectively I need an LPOLESTR* to begin and end of this array. How is that done?

Thx in advance

like image 923
Michbeckable Avatar asked Jul 07 '26 04:07

Michbeckable


1 Answers

ATL has a set of macros for string conversions. In your case, you can use:

LPOLESTR olestr = A2OLE(std_str.c_str());

Note that OLESTR is basically a wchar_t*, so if you're using std::wstring (or wide char string literals) you don't even need the macro:

LPOLESTR olestr = std_wstr.c_str();
like image 91
eran Avatar answered Jul 10 '26 11:07

eran