Click to See Complete Forum and Search --> : UNICODE question


Matthew Smith
March 30th, 1999, 11:45 PM
Hi, I have the following few lines in my program, that get called in OnInitialUpdate() for a RichEditView doc/view app.

CHARFORMAT cfm;

cfm.cbSize = sizeof(cfm);

cfm.dwMask = CFM_FACE | CFM_BOLD;

cfm.dwEffects = CFE_BOLD;

_tcscpy(cfm.szFaceName, _T("Arial"));

theCtrl.SetDefaultCharFormat(cfm);

When compiling with _UNICODE, that code fails on the _tcscpy line, with the following error:

error C2664: 'wcscpy' : cannot convert parameter 1 from 'char [32]' to 'unsigned short *'

Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

How can I get this to work with _UNICODE?


thanks,

-Matt

Christian Busch
March 31st, 1999, 12:50 AM
In the header file AFXPRIV.H are numerous string conversion macros:

A2BSTR OLE2A T2A W2A

A2COLE OLE2BSTR T2BSTR W2BSTR

A2CT OLE2CA T2CA W2CA

A2CW OLE2CT T2COLE W2COLE

A2OLE OLE2CW T2CW W2CT

A2T OLE2T T2OLE W2OLE

A2W OLE2W T2W W2T



W2A will solve your problem and convert the UNICODE string to normal ASCII

Dieter Gollwitzer
March 31st, 1999, 07:50 AM
Use _UNICODE and UNICODE (without underline)


The following codefragment is from richedit.h:


#if (_RICHEDIT_VER >= 0x0200)

#ifdef UNICODE

#define CHARFORMAT CHARFORMATW

#else

#define CHARFORMAT CHARFORMATA

#endif /* UNICODE */

#else

#define CHARFORMAT CHARFORMATA

#endif /* _RICHEDIT_VER >= 0x0200 */