You must know the code page used by the file. Then read the file content into a buffer and use
MultiByteToWideChar[
^] passing the code page number to convert it to Unicode.
With Japanese text, the code page number may be 932 (Shift-JIS), 2032 (EUC-JP), 50220 to 50222 (ISO-2022), or 51932. See also
Code Page Identifiers[
^].
[EDIT]
An untested (but compiling) example:
#include <io.h>
LPWSTR ReadAnsiFile(LPCTSTR lpszFileName, UINT nCP)
{
WCHAR *lpszWideString = NULL;
FILE * f = _tfopen(lpszFileName, _T("rb"));
if (f)
{
long nAnsiLen = _filelength(_fileno(f));
char *buf = new char[nAnsiLen];
fread(buf, 1, nAnsiLen, f);
int nWideLen = ::MultiByteToWideChar(nCP, 0, buf, nAnsiLen, NULL, 0);
if (nWideLen > 0)
{
lpszWideString = new wchar_t[nWideLen + 1];
::MultiByteToWideChar(nCP, 0, buf, nAnsiLen, lpszWideString, nWideLen);
lpszWideString[nWideLen] = L'\0';
}
delete [] buf;
fclose(f);
}
return lpszWideString;
}
When the file has been created on the same system by the same user, using
CP_ACP
may be used. Otherwise, the code page number must be known.
[EDIT 2: Added inclusion of io.h to code]