C++ Convert Sytem::String^ to LPCOLESTR
问题 I write in mixed mode (C++/CLI) and I can not resolve this problem: String ^progID = "Matrikon.OPC.Server"; CLSID clsid; HRESULT result = CLSIDFromProgID(progID, &clsid); error C2664: 'CLSIDFromProgID' : cannot convert parameter 1 from 'System::String ^' to 'LPCOLESTR' How can I convert String^ to LPCOLESTR ? Thanks! 回答1: First, lets convert System::String to char* IntPtr p = Marshal::StringToHGlobalAnsi(progID); char *pNewCharStr = static_cast<char*>(p.ToPointer()); second, casting char * to