unicode vs. ansi strings in WriteFile

P

Paul

Hi,

I am extending an existing MFC app to use Unicode (for a
Japanese version of the interface elements). The app's
purpose is to control a peripheral device through the
serial port, and the device only understands ansi strings
(in fact, I synthesize a character stream and send it as
though it was typed into a terminal). The problem seems to
be that the VC++ 6 linker insists that if I use the
#define UNICODE and _UNICODE preprocessor directives and
the wWinMainCRTStartup entry point, all my calls to
ReadFile and WriteFile will happen in Unicode! In other
words, my Unicode app will always send Unicode text
through the serial port, which screws up communications
with the device. There must be a way of forcing the
Read/WriteFile functions to call their ANSI versions
instead of the Unicode ones, or line printers would go
nuts, right? How do I link Read/WriteFile to the ANSI
versions?
 
C

Carl Daniel [VC++ MVP]

Paul said:
Hi,

I am extending an existing MFC app to use Unicode (for a
Japanese version of the interface elements). The app's
purpose is to control a peripheral device through the
serial port, and the device only understands ansi strings
(in fact, I synthesize a character stream and send it as
though it was typed into a terminal). The problem seems to
be that the VC++ 6 linker insists that if I use the
#define UNICODE and _UNICODE preprocessor directives and
the wWinMainCRTStartup entry point, all my calls to
ReadFile and WriteFile will happen in Unicode! In other
words, my Unicode app will always send Unicode text
through the serial port, which screws up communications
with the device. There must be a way of forcing the
Read/WriteFile functions to call their ANSI versions
instead of the Unicode ones, or line printers would go
nuts, right? How do I link Read/WriteFile to the ANSI
versions?

That's not your problem (and I don't know exactly what is your problem).

ReadFile and WriteFile deal solely in bytes - they know nothing of
characters, character sets, ASCII or Unicode. In short - there is no
"Unicode" version of these APIs.

If you can show some code that you're using to interact with the serial
port, I'm sure someone can spot where you're getting a "helpful" unicode
conversion that you're not aware of.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top