diff options
author | 2016-07-24 14:42:37 -0400 | |
---|---|---|
committer | 2016-07-24 14:42:37 -0400 | |
commit | e681889d8877ac555cbeb2aac717c773fc00d5b0 (patch) | |
tree | 03eb415cfb7bd4bb5ed4d0819ac82be861da95b6 /src/lib/netlist/plib/pdynlib.cpp | |
parent | 1e17c2e6f77e5b21d109e16c13f318743504e294 (diff) | |
parent | 1344df74969df64fe90555d51675921882249c93 (diff) |
Merge pull request #1139 from GiuseppeGorgoglione/master
Fix for netlist library when built for WINDOWS with UNICODE defined
Diffstat (limited to 'src/lib/netlist/plib/pdynlib.cpp')
-rw-r--r-- | src/lib/netlist/plib/pdynlib.cpp | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/src/lib/netlist/plib/pdynlib.cpp b/src/lib/netlist/plib/pdynlib.cpp index 6aa1f180aa3..2088ab47c1b 100644 --- a/src/lib/netlist/plib/pdynlib.cpp +++ b/src/lib/netlist/plib/pdynlib.cpp @@ -5,9 +5,54 @@ * */ -#include <plib/pdynlib.h> +#include "pdynlib.h" + #ifdef WIN32 #include "windows.h" +#include "palloc.h" + +namespace plib { +CHAR *astring_from_utf8(const char *utf8string) +{ + WCHAR *wstring; + int char_count; + CHAR *result; + + // convert MAME string (UTF-8) to UTF-16 + char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, nullptr, 0); + wstring = (WCHAR *)alloca(char_count * sizeof(*wstring)); + MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, wstring, char_count); + + // convert UTF-16 to "ANSI code page" string + char_count = WideCharToMultiByte(CP_ACP, 0, wstring, -1, nullptr, 0, nullptr, nullptr); + result = palloc_array<CHAR>(char_count); + if (result != nullptr) + WideCharToMultiByte(CP_ACP, 0, wstring, -1, result, char_count, nullptr, nullptr); + + return result; +} + +WCHAR *wstring_from_utf8(const char *utf8string) +{ + int char_count; + WCHAR *result; + + // convert MAME string (UTF-8) to UTF-16 + char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, nullptr, 0); + result = palloc_array<WCHAR>(char_count); + if (result != nullptr) + MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count); + + return result; +} +} + +#ifdef UNICODE +#define tstring_from_utf8 plib::wstring_from_utf8 +#else // !UNICODE +#define tstring_from_utf8 plib::astring_from_utf8 +#endif // UNICODE + #else #include <dlfcn.h> #endif @@ -18,14 +63,16 @@ dynlib::dynlib(const pstring libname) { #ifdef WIN32 //fprintf(stderr, "win: loading <%s>\n", libname.cstr()); + TCHAR *buffer = tstring_from_utf8(libname.cstr()); if (libname != "") - m_lib = LoadLibrary(libname.cstr()); + m_lib = LoadLibrary(buffer); else m_lib = GetModuleHandle(nullptr); if (m_lib != nullptr) m_isLoaded = true; //else // fprintf(stderr, "win: library <%s> not found!\n", libname.cstr()); + pfree_array(buffer); #else //printf("loading <%s>\n", libname.cstr()); if (libname != "") @@ -44,8 +91,9 @@ dynlib::dynlib(const pstring path, const pstring libname) { // printf("win: loading <%s>\n", libname.cstr()); #ifdef WIN32 + TCHAR *buffer = tstring_from_utf8(libname.cstr()); if (libname != "") - m_lib = LoadLibrary(libname.cstr()); + m_lib = LoadLibrary(buffer); else m_lib = GetModuleHandle(nullptr); if (m_lib != nullptr) @@ -54,6 +102,7 @@ dynlib::dynlib(const pstring path, const pstring libname) { //printf("win: library <%s> not found!\n", libname.cstr()); } + pfree_array(buffer); #else //printf("loading <%s>\n", libname.cstr()); if (libname != "") |