2011-10-13 2 views
1

J'ai un tableau de chaînes comme ceci:std :: string à LPOLESTR

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

Maintenant, je veux utiliser cette fonction:

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

T est dans mon cas LPOLESTR. J'ai donc besoin de convertir le tableau de std :: string en LPOLESTR respectivement j'ai besoin d'un LPOLESTR * pour commencer et terminer ce tableau. Comment cela est-il fait?

Thx à l'avance

Répondre

5

ATL a une set of macros pour les conversions de chaînes. Dans votre cas, vous pouvez utiliser:

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

Notez que OLESTR est essentiellement un * wchar_t, donc si vous utilisez std :: wstring (ou littéraux large chaîne de char) vous ne même pas besoin de la macro:

LPOLESTR olestr = std_wstr.c_str(); 
+0

Cela fonctionne! THX! – Michbeckable