diff --git a/win32/_tfwopen.cpp b/win32/_tfwopen.cpp index f13c301b..3ec11451 100644 --- a/win32/_tfwopen.cpp +++ b/win32/_tfwopen.cpp @@ -192,6 +192,12 @@ WideToUtf8::WideToUtf8(const wchar_t *wideChars) { WideCharToMultiByte(CP_UTF8,0,wideChars,-1,utf8Chars,requiredChars,NULL,NULL); } +MS932ToWide::MS932ToWide(const char *ms932Chars) { + int requiredChars = MultiByteToWideChar(932,0,ms932Chars,-1,wideChars,0); + wideChars = new wchar_t[requiredChars]; + MultiByteToWideChar(932,0,ms932Chars,-1,wideChars,requiredChars); +} + extern "C" FILE *_tfwopen(const char *filename, const char *mode ) { wchar_t mode_w[30]; lstrcpyn(mode_w,Utf8ToWide(mode),29); diff --git a/win32/_tfwopen.h b/win32/_tfwopen.h index 52749dae..18471012 100644 --- a/win32/_tfwopen.h +++ b/win32/_tfwopen.h @@ -215,6 +215,15 @@ public: operator char *() { return utf8Chars; } }; +class MS932ToWide { +private: + wchar_t *wideChars; +public: + MS932ToWide(const char *ms932Chars); + ~MS932ToWide() { delete [] wideChars; } + operator wchar_t *() { return wideChars; } +}; + namespace std { class u8nifstream: public std::ifstream { diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp index cbcf7cc3..81571934 100644 --- a/win32/wsnes9x.cpp +++ b/win32/wsnes9x.cpp @@ -5245,7 +5245,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer) if (InfoScore((char *)HeaderBuffer) > 1) { EHi = true; - _tcsncpy(namebuffer, _tFromChar((char *)HeaderBuffer), 21); + _tcsncpy(namebuffer, _tFromMS932((char *)HeaderBuffer), 21); } } @@ -5263,7 +5263,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer) ROMFile.read(HiHead, INFO_LEN); int HiScore = InfoScore(HiHead); - _tcsncpy(namebuffer, _tFromChar(LoScore > HiScore ? LoHead : HiHead), 21); + _tcsncpy(namebuffer, _tFromMS932(LoScore > HiScore ? LoHead : HiHead), 21); if (filestats.st_size - HeaderSize >= 0x20000) { @@ -5273,7 +5273,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer) if (IntLScore > LoScore && IntLScore > HiScore) { - _tcsncpy(namebuffer, _tFromChar(LoHead), 21); + _tcsncpy(namebuffer, _tFromMS932(LoHead), 21); } } } @@ -5282,7 +5282,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer) char buf[21]; ROMFile.seekg(0x7FC0 + HeaderSize, ios::beg); ROMFile.read(buf, 21); - _tcsncpy(namebuffer,_tFromChar(buf),21); + _tcsncpy(namebuffer,_tFromMS932(buf),21); } } ROMFile.close(); diff --git a/win32/wsnes9x.h b/win32/wsnes9x.h index fb7c81c6..0f618be0 100644 --- a/win32/wsnes9x.h +++ b/win32/wsnes9x.h @@ -216,9 +216,11 @@ #ifdef UNICODE #define _tToChar WideToUtf8 #define _tFromChar Utf8ToWide +#define _tFromMS932 MS932ToWide #else #define _tToChar #define _tFromChar +#define _tFromMS932 #endif /****************************************************************************/