tags:

views:

63

answers:

2

Am I right in thinking that the MFC class CMemFile is cannot be used to write unicode data to because it uses BYTE* which is defined as unsigned char BYTE?

The line line that actually writes the data in CMemFile::Write is

 Memcpy((BYTE*)m_lpBuffer + m_nPosition, (BYTE*)lpBuf, nCount);

and if so can I replace BYTE with wchar_t in my own implementation of CMemfIle to get it working with unicode?

Thanks You Paul..

+2  A: 

I don't see why it couldn't be used directly.

The only issue is that when you're doing memory copying, you can't interchange the character count with the byte count.

Jon Seigel
A: 

Files are binary so always read/write bytes and use an encoding layer to convert to/from string unless you are sure the data is in ASCII encoding.

No, you need an encoder/decoder. For Unicode you need a unicode header followed by encoded characters. The exact binary values of encoded characters could be different based on the unicode encoding (UTF-7, UTF-8, UTF-16, UTF-32, etc).

Sheng Jiang 蒋晟
Do you mean recording the starting offsets and string lengths?
Paul