Article ID: 329071
Article Last Modified on 11/21/2006
APPLIES TO
- Microsoft Foundation Class Library 4.2
This article was previously published under Q329071
SYMPTOMS
In a Unicode build of an MFC application, when you pass the CString object to a call to CInternetFile::ReadString, the CString object may not contain Unicode text. This occurs when the file that is being read is not already a Unicode file.
CAUSE
The ReadString method does not convert non-Unicode text to Unicode. For example, if the file that is being read is an ANSI file, the buffer for the CString object is ANSI also.
WORKAROUND
To work around this problem manually, convert the text by using the MultiByteToWideChar function. See the "References" section of this article for more information about this function.
The first parameter of the MultiByteToWideChar function specifies the code-page to use when the function converts the text to Unicode. Typically, you might use CP_ACP (for ANSI). However, if the code-page in the file is different from the code-page of your system, you must determine the code-page in the file, and then pass this as the first parameter. In most cases, this information is located in the charset metadata in the file. For example,
<meta http-equiv="Content-Type" content="text/html; charset=x-sjis">
indicates a Japanese language text. Therefore, to convert this text to Unicode, you call MultiByteToWideChar(932, ....), where 932 is the code-page identifier for Japan.
STATUS
This behavior is by design.
REFERENCES
For more information, visit the following Microsoft Web site:
Keywords: kbprb KB329071