c++ exception message in messagebox

1k views Asked by At

Seems simple but can't find the solution.

I want something like this

catch (Exception^ ex)
{
    MessageBoxA(NULL, ex->ToString(),  "", MB_OK);
}

But it says Plattform::string ^ is incompatible with LPCSTR.

1

There are 1 answers

3
Starl1ght On BEST ANSWER

Platform::String is .NET class, which is of course is not compatible with good old char*.

To fix this you need to do 2 things.

First, convert Platform::String to wchar_t*, since it's unicode string. Use method Data()

Second, use MessageBoxW, since we are working with unicode, not ANSI.

Resulting code should look like this:

MessageBoxW(NULL, ex->ToString()->Data(),  "", MB_OK);