The 2nd argument of String::Format() is a param array. Roughly similar to ...
as used in the C language for functions like printf(). Under the hood, it is a managed array of objects, the declaration looks like this in C++/CLI syntax:
static String^ Format(String^ format, ... array<Object^>^ args);
So a hard requirement is that the arguments you pass are convertible to System::Object. The Format() method relies on these objects implementing ToString(), all managed objects do.
No problem with AString of course, it is a managed string and its ToString() method simply returns the same string.
No problem with the string literal, the compiler implicitly converts any string literal to System::String. It automatically emits the code necessary to create the String object. Note that prefixing the literal with L isn't necessary.
Big problem with wchar_t*
, it is an unmanaged pointer. They are never implicitly convertible to any managed type. System::IntPtr would be the closest possible match but it is not useful at all since this is just an untyped pointer value. So you have to write the code yourself to make the conversion. You already know what it looks like:
String^ CString = String::Format("{0}.", gcnew String(szErrMsg));