5

I hope that the title was good enough to help explain what is needed. After solving this much of my project should be done.

When I did this

    char e[1000] = "HELLO";
    CString msg;
    msg.Format(_T("%s"), e);
    MessageBox(msg);

the messagebox just show me random words like "㹙癞鞮㹙癞鞮" instead of the "HELLO" i wanted. How do I solve this problem??

Helps would be appreciated. Thank You

Ashton
  • 83
  • 1
  • 3
  • 12

1 Answers1

4

First of all, are you really using MessageBox API that way. Check the MSDN Documentation. Now to your question,

char e[1000] = "HELLO";
CString msg;
msg.Format(_T("%S"), e); // Mind the caps "S"
MessageBox( NULL, msg, _T("Hi"), NULL );

I think, you do not even need to Format data here. You can use::

TCHAR e[1000] = _T("HELLO") ;
MessageBox( NULL, e, _T("Hi"), NULL ) ;

This way, if _UNICODE is defined, both TCHAR and MessageBox would get chosen as WCHAR and MessageBoxW and if not defined as char and MessageBoxA.

Abhineet
  • 5,320
  • 1
  • 25
  • 43
  • `AfxMessageBox` work for me, see: https://stackoverflow.com/questions/15738503/mfc-c-how-do-i-display-a-const-char-value-in-messagebox – yu yang Jian Jun 21 '21 at 17:22