Changed strconv.[cpp|h] functions to return their results as std::string and std::wstring

This commit is contained in:
Nathan Woods 2016-07-24 22:55:00 -04:00
parent 59dafc2261
commit ab73291e47
19 changed files with 194 additions and 324 deletions

View File

@ -43,12 +43,8 @@ consolewin_info::consolewin_info(debugger_windows_interface &debugger) :
m_devices_menu = CreatePopupMenu(); m_devices_menu = CreatePopupMenu();
for (device_image_interface &img : iter) for (device_image_interface &img : iter)
{ {
TCHAR *tc_buf = tstring_from_utf8(string_format("%s : %s", img.device().name(), img.exists() ? img.filename() : "[no image]").c_str()); auto tc_buf = tstring_from_utf8(string_format("%s : %s", img.device().name(), img.exists() ? img.filename() : "[no image]").c_str());
if (tc_buf != nullptr) AppendMenu(m_devices_menu, MF_ENABLED, 0, tc_buf.c_str());
{
AppendMenu(m_devices_menu, MF_ENABLED, 0, tc_buf);
osd_free(tc_buf);
}
} }
AppendMenu(GetMenu(window()), MF_ENABLED | MF_POPUP, (UINT_PTR)m_devices_menu, TEXT("Images")); AppendMenu(GetMenu(window()), MF_ENABLED | MF_POPUP, (UINT_PTR)m_devices_menu, TEXT("Images"));
} }
@ -195,12 +191,8 @@ void consolewin_info::update_menu()
AppendMenu(devicesubmenu, flags_for_exists, new_item + DEVOPTION_CASSETTE_FASTFORWARD, TEXT("Fast Forward")); AppendMenu(devicesubmenu, flags_for_exists, new_item + DEVOPTION_CASSETTE_FASTFORWARD, TEXT("Fast Forward"));
} }
TCHAR *tc_buf = tstring_from_utf8(string_format("%s :%s", img.device().name(), img.exists() ? img.filename() : "[empty slot]").c_str()); auto tc_buf = tstring_from_utf8(string_format("%s :%s", img.device().name(), img.exists() ? img.filename() : "[empty slot]").c_str());
if (tc_buf != nullptr) ModifyMenu(m_devices_menu, cnt, MF_BYPOSITION | MF_POPUP, (UINT_PTR)devicesubmenu, tc_buf.c_str());
{
ModifyMenu(m_devices_menu, cnt, MF_BYPOSITION | MF_POPUP, (UINT_PTR)devicesubmenu, tc_buf);
osd_free(tc_buf);
}
cnt++; cnt++;
} }
@ -223,9 +215,9 @@ bool consolewin_info::handle_command(WPARAM wparam, LPARAM lparam)
{ {
std::string filter; std::string filter;
build_generic_filter(img, false, filter); build_generic_filter(img, false, filter);
LPTSTR t_filter = tstring_from_utf8(filter.c_str());
if (t_filter)
{ {
auto t_filter = tstring_from_utf8(filter.c_str());
// convert a pipe-char delimited string into a NUL delimited string // convert a pipe-char delimited string into a NUL delimited string
for (int i = 0; t_filter[i] != '\0'; i++) for (int i = 0; t_filter[i] != '\0'; i++)
{ {
@ -242,7 +234,7 @@ bool consolewin_info::handle_command(WPARAM wparam, LPARAM lparam)
ofn.lpstrFile = selectedFilename; ofn.lpstrFile = selectedFilename;
ofn.lpstrFile[0] = '\0'; ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = MAX_PATH; ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = t_filter; ofn.lpstrFilter = t_filter.c_str();
ofn.nFilterIndex = 1; ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = nullptr; ofn.lpstrFileTitle = nullptr;
ofn.nMaxFileTitle = 0; ofn.nMaxFileTitle = 0;
@ -251,24 +243,18 @@ bool consolewin_info::handle_command(WPARAM wparam, LPARAM lparam)
if (GetOpenFileName(&ofn)) if (GetOpenFileName(&ofn))
{ {
char *utf8_buf = utf8_from_tstring(selectedFilename); auto utf8_buf = utf8_from_tstring(selectedFilename);
if (utf8_buf != nullptr) img->load(utf8_buf.c_str());
{
img->load(utf8_buf);
osd_free(utf8_buf);
} }
} }
osd_free(t_filter);
}
} }
return true; return true;
case DEVOPTION_CREATE: case DEVOPTION_CREATE:
{ {
std::string filter; std::string filter;
build_generic_filter(img, true, filter); build_generic_filter(img, true, filter);
LPTSTR t_filter = tstring_from_utf8(filter.c_str());
if (t_filter)
{ {
auto t_filter = tstring_from_utf8(filter.c_str());
// convert a pipe-char delimited string into a NUL delimited string // convert a pipe-char delimited string into a NUL delimited string
for (int i = 0; t_filter[i] != '\0'; i++) for (int i = 0; t_filter[i] != '\0'; i++)
{ {
@ -285,7 +271,7 @@ bool consolewin_info::handle_command(WPARAM wparam, LPARAM lparam)
ofn.lpstrFile = selectedFilename; ofn.lpstrFile = selectedFilename;
ofn.lpstrFile[0] = '\0'; ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = MAX_PATH; ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = t_filter; ofn.lpstrFilter = t_filter.c_str();
ofn.nFilterIndex = 1; ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = nullptr; ofn.lpstrFileTitle = nullptr;
ofn.nMaxFileTitle = 0; ofn.nMaxFileTitle = 0;
@ -294,15 +280,10 @@ bool consolewin_info::handle_command(WPARAM wparam, LPARAM lparam)
if (GetSaveFileName(&ofn)) if (GetSaveFileName(&ofn))
{ {
char *utf8_buf = utf8_from_tstring(selectedFilename); auto utf8_buf = utf8_from_tstring(selectedFilename);
if (utf8_buf != nullptr) img->create(utf8_buf.c_str(), img->device_get_indexed_creatable_format(0), nullptr);
{
img->create(utf8_buf, img->device_get_indexed_creatable_format(0), nullptr);
osd_free(utf8_buf);
} }
} }
osd_free(t_filter);
}
} }
return true; return true;
case DEVOPTION_CLOSE: case DEVOPTION_CLOSE:

View File

@ -268,9 +268,8 @@ HWND debugview_info::create_source_combobox(HWND parent, LONG_PTR userdata)
int const length = strlen(source->name()); int const length = strlen(source->name());
if (length > maxlength) if (length > maxlength)
maxlength = length; maxlength = length;
TCHAR *t_name = tstring_from_utf8(source->name()); auto t_name = tstring_from_utf8(source->name());
SendMessage(result, CB_ADDSTRING, 0, (LPARAM)t_name); SendMessage(result, CB_ADDSTRING, 0, (LPARAM)t_name.c_str());
osd_free(t_name);
} }
if (cursource != nullptr) if (cursource != nullptr)
{ {

View File

@ -79,12 +79,8 @@ void editwin_info::set_editwnd_bounds(RECT const &bounds)
void editwin_info::set_editwnd_text(char const *text) void editwin_info::set_editwnd_text(char const *text)
{ {
TCHAR *tc_buffer = tstring_from_utf8(text); auto tc_buffer = tstring_from_utf8(text);
if (tc_buffer != nullptr) SendMessage(m_editwnd, WM_SETTEXT, (WPARAM)0, (LPARAM)tc_buffer.c_str());
{
SendMessage(m_editwnd, WM_SETTEXT, (WPARAM)0, (LPARAM)tc_buffer);
osd_free(tc_buffer);
}
} }
@ -190,11 +186,9 @@ LRESULT editwin_info::edit_proc(UINT message, WPARAM wparam, LPARAM lparam)
m_last_history = m_history_count - 1; m_last_history = m_history_count - 1;
// process // process
char *utf8_buffer = utf8_from_tstring(buffer);
if (utf8_buffer != nullptr)
{ {
process_string(utf8_buffer); auto utf8_buffer = utf8_from_tstring(buffer);
osd_free(utf8_buffer); process_string(utf8_buffer.c_str());
} }
break; break;
} }

View File

@ -27,10 +27,9 @@ ui_metrics::ui_metrics(osd_options const &options) :
char const *const face = options.debugger_font(); char const *const face = options.debugger_font();
// create a standard font // create a standard font
TCHAR *t_face = tstring_from_utf8((!*face || !strcmp(OSDOPTVAL_AUTO, face)) ? "Lucida Console" : face); auto t_face = tstring_from_utf8((!*face || !strcmp(OSDOPTVAL_AUTO, face)) ? "Lucida Console" : face);
m_debug_font = CreateFont(-MulDiv((size <= 0) ? 9 : size, GetDeviceCaps(temp_dc, LOGPIXELSY), 72), 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, m_debug_font = CreateFont(-MulDiv((size <= 0) ? 9 : size, GetDeviceCaps(temp_dc, LOGPIXELSY), 72), 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH, t_face); ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH, t_face.c_str());
osd_free(t_face);
if (m_debug_font == nullptr) if (m_debug_font == nullptr)
fatalerror("Unable to create debugger font\n"); fatalerror("Unable to create debugger font\n");

View File

@ -14,6 +14,7 @@
// MAME headers // MAME headers
#include "osdcore.h" #include "osdcore.h"
#include "strformat.h"
// MAMEOS headers // MAMEOS headers
#include "strconv.h" #include "strconv.h"
@ -47,6 +48,7 @@ private:
bool m_is_first; // true if this is the first entry bool m_is_first; // true if this is the first entry
entry m_entry; // current entry's data entry m_entry; // current entry's data
WIN32_FIND_DATA m_data; // current raw data WIN32_FIND_DATA m_data; // current raw data
std::string m_name; // converted name of directory
}; };
//============================================================ //============================================================
@ -69,8 +71,6 @@ win_directory::win_directory()
win_directory::~win_directory() win_directory::~win_directory()
{ {
// free any data associated // free any data associated
if (m_entry.name != nullptr)
osd_free((void *)m_entry.name);
if (m_find != INVALID_HANDLE_VALUE) if (m_find != INVALID_HANDLE_VALUE)
FindClose(m_find); FindClose(m_find);
} }
@ -82,13 +82,6 @@ win_directory::~win_directory()
const directory::entry *win_directory::read() const directory::entry *win_directory::read()
{ {
// if we've previously allocated a name, free it now
if (m_entry.name != nullptr)
{
osd_free((void *)m_entry.name);
m_entry.name = nullptr;
}
// if this isn't the first file, do a find next // if this isn't the first file, do a find next
if (!m_is_first) if (!m_is_first)
{ {
@ -98,7 +91,8 @@ const directory::entry *win_directory::read()
m_is_first = false; m_is_first = false;
// extract the data // extract the data
m_entry.name = utf8_from_tstring(m_data.cFileName); utf8_from_tstring(m_name, m_data.cFileName);
m_entry.name = m_name.c_str();
m_entry.type = win_attributes_to_entry_type(m_data.dwFileAttributes); m_entry.type = win_attributes_to_entry_type(m_data.dwFileAttributes);
m_entry.size = m_data.nFileSizeLow | (std::uint64_t(m_data.nFileSizeHigh) << 32); m_entry.size = m_data.nFileSizeLow | (std::uint64_t(m_data.nFileSizeHigh) << 32);
m_entry.last_modified = win_time_point_from_filetime(&m_data.ftLastWriteTime); m_entry.last_modified = win_time_point_from_filetime(&m_data.ftLastWriteTime);
@ -114,20 +108,14 @@ bool win_directory::open_impl(std::string const &dirname)
{ {
assert(m_find == INVALID_HANDLE_VALUE); assert(m_find == INVALID_HANDLE_VALUE);
// convert the path to TCHARs
std::unique_ptr<TCHAR, void (*)(void *)> const t_dirname(tstring_from_utf8(dirname.c_str()), &osd_free);
if (!t_dirname)
return false;
// append \*.* to the directory name // append \*.* to the directory name
auto const dirfilter_size = _tcslen(t_dirname.get()) + 5; std::string dirfilter = string_format("%s\\*.*", dirname);
std::unique_ptr<TCHAR []> dirfilter;
try { dirfilter.reset(new TCHAR[dirfilter_size]); } // convert the path to TCHARs
catch (...) { return false; } auto t_dirfilter = tstring_from_utf8(dirfilter.c_str());
_sntprintf(dirfilter.get(), dirfilter_size, TEXT("%s\\*.*"), t_dirname.get());
// attempt to find the first file // attempt to find the first file
m_find = FindFirstFileEx(dirfilter.get(), FindExInfoStandard, &m_data, FindExSearchNameMatch, nullptr, 0); m_find = FindFirstFileEx(t_dirfilter.c_str(), FindExInfoStandard, &m_data, FindExSearchNameMatch, nullptr, 0);
return m_find != INVALID_HANDLE_VALUE; return m_find != INVALID_HANDLE_VALUE;
} }

View File

@ -184,14 +184,7 @@ osd_file::error osd_file::open(std::string const &orig_path, UINT32 openflags, p
return win_open_ptty(path, openflags, file, filesize); return win_open_ptty(path, openflags, file, filesize);
// convert path to TCHAR // convert path to TCHAR
TCHAR *t_path = tstring_from_utf8(path.c_str()); auto t_path = tstring_from_utf8(path.c_str());
osd_disposer<TCHAR> t_path_disposer(t_path);
if (!t_path)
return error::OUT_OF_MEMORY;
// convert the path into something Windows compatible
for (TCHAR *src = t_path; *src != 0; src++)
*src = /* ('/' == *src) ? '\\' : */ *src;
// select the file open modes // select the file open modes
DWORD disposition, access, sharemode; DWORD disposition, access, sharemode;
@ -213,25 +206,25 @@ osd_file::error osd_file::open(std::string const &orig_path, UINT32 openflags, p
} }
// attempt to open the file // attempt to open the file
HANDLE h = CreateFile(t_path, access, sharemode, nullptr, disposition, 0, nullptr); HANDLE h = CreateFile(t_path.c_str(), access, sharemode, nullptr, disposition, 0, nullptr);
if (INVALID_HANDLE_VALUE == h) if (INVALID_HANDLE_VALUE == h)
{ {
DWORD err = GetLastError(); DWORD err = GetLastError();
// create the path if necessary // create the path if necessary
if ((ERROR_PATH_NOT_FOUND == err) && (openflags & OPEN_FLAG_CREATE) && (openflags & OPEN_FLAG_CREATE_PATHS)) if ((ERROR_PATH_NOT_FOUND == err) && (openflags & OPEN_FLAG_CREATE) && (openflags & OPEN_FLAG_CREATE_PATHS))
{ {
TCHAR *pathsep = _tcsrchr(t_path, '\\'); TCHAR *pathsep = _tcsrchr(&t_path[0], '\\');
if (pathsep != nullptr) if (pathsep != nullptr)
{ {
// create the path up to the file // create the path up to the file
*pathsep = 0; *pathsep = 0;
err = create_path_recursive(t_path); err = create_path_recursive(&t_path[0]);
*pathsep = '\\'; *pathsep = '\\';
// attempt to reopen the file // attempt to reopen the file
if (err == NO_ERROR) if (err == NO_ERROR)
{ {
h = CreateFile(t_path, access, sharemode, nullptr, disposition, 0, nullptr); h = CreateFile(t_path.c_str(), access, sharemode, nullptr, disposition, 0, nullptr);
err = GetLastError(); err = GetLastError();
} }
} }
@ -287,15 +280,12 @@ osd_file::error osd_file::openpty(ptr &file, std::string &name)
osd_file::error osd_file::remove(std::string const &filename) osd_file::error osd_file::remove(std::string const &filename)
{ {
TCHAR *tempstr = tstring_from_utf8(filename.c_str()); auto tempstr = tstring_from_utf8(filename.c_str());
if (!tempstr)
return error::OUT_OF_MEMORY;
error filerr = error::NONE; error filerr = error::NONE;
if (!DeleteFile(tempstr)) if (!DeleteFile(tempstr.c_str()))
filerr = win_error_to_file_error(GetLastError()); filerr = win_error_to_file_error(GetLastError());
osd_free(tempstr);
return filerr; return filerr;
} }
@ -309,7 +299,6 @@ int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UIN
{ {
DISK_GEOMETRY dg; DISK_GEOMETRY dg;
DWORD bytesRead; DWORD bytesRead;
TCHAR *t_filename;
HANDLE file; HANDLE file;
int result; int result;
@ -318,11 +307,8 @@ int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UIN
return FALSE; return FALSE;
// do a create file on the drive // do a create file on the drive
t_filename = tstring_from_utf8(filename); auto t_filename = tstring_from_utf8(filename);
if (t_filename == nullptr) file = CreateFile(t_filename.c_str(), GENERIC_READ, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, nullptr);
return FALSE;
file = CreateFile(t_filename, GENERIC_READ, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, nullptr);
osd_free(t_filename);
if (file == INVALID_HANDLE_VALUE) if (file == INVALID_HANDLE_VALUE)
return FALSE; return FALSE;
@ -358,9 +344,7 @@ int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UIN
std::unique_ptr<osd::directory::entry> osd_stat(const std::string &path) std::unique_ptr<osd::directory::entry> osd_stat(const std::string &path)
{ {
// convert the path to TCHARs // convert the path to TCHARs
std::unique_ptr<TCHAR, void (*)(void *)> const t_path(tstring_from_utf8(path.c_str()), &osd_free); auto t_path = tstring_from_utf8(path.c_str());
if (!t_path)
return nullptr;
// is this path a root directory (e.g. - C:)? // is this path a root directory (e.g. - C:)?
WIN32_FIND_DATA find_data; WIN32_FIND_DATA find_data;
@ -368,13 +352,13 @@ std::unique_ptr<osd::directory::entry> osd_stat(const std::string &path)
if (isalpha(path[0]) && (path[1] == ':') && (path[2] == '\0')) if (isalpha(path[0]) && (path[1] == ':') && (path[2] == '\0'))
{ {
// need to do special logic for root directories // need to do special logic for root directories
if (!GetFileAttributesEx(t_path.get(), GetFileExInfoStandard, &find_data.dwFileAttributes)) if (!GetFileAttributesEx(t_path.c_str(), GetFileExInfoStandard, &find_data.dwFileAttributes))
find_data.dwFileAttributes = INVALID_FILE_ATTRIBUTES; find_data.dwFileAttributes = INVALID_FILE_ATTRIBUTES;
} }
else else
{ {
// attempt to find the first file // attempt to find the first file
HANDLE find = FindFirstFileEx(t_path.get(), FindExInfoStandard, &find_data, FindExSearchNameMatch, nullptr, 0); HANDLE find = FindFirstFileEx(t_path.c_str(), FindExInfoStandard, &find_data, FindExSearchNameMatch, nullptr, 0);
if (find == INVALID_HANDLE_VALUE) if (find == INVALID_HANDLE_VALUE)
return nullptr; return nullptr;
FindClose(find); FindClose(find);
@ -404,23 +388,15 @@ std::unique_ptr<osd::directory::entry> osd_stat(const std::string &path)
osd_file::error osd_get_full_path(std::string &dst, std::string const &path) osd_file::error osd_get_full_path(std::string &dst, std::string const &path)
{ {
// convert the path to TCHARs // convert the path to TCHARs
TCHAR *t_path = tstring_from_utf8(path.c_str()); auto t_path = tstring_from_utf8(path.c_str());
osd_disposer<TCHAR> t_path_disposer(t_path);
if (!t_path)
return osd_file::error::OUT_OF_MEMORY;
// cannonicalize the path // cannonicalize the path
TCHAR buffer[MAX_PATH]; TCHAR buffer[MAX_PATH];
if (!GetFullPathName(t_path, ARRAY_LENGTH(buffer), buffer, nullptr)) if (!GetFullPathName(t_path.c_str(), ARRAY_LENGTH(buffer), buffer, nullptr))
return win_error_to_file_error(GetLastError()); return win_error_to_file_error(GetLastError());
// convert the result back to UTF-8 // convert the result back to UTF-8
char *result = utf8_from_tstring(buffer); utf8_from_tstring(dst, buffer);
osd_disposer<char> result_disposer(result);
if (!result)
return osd_file::error::OUT_OF_MEMORY;
dst = result;
return osd_file::error::NONE; return osd_file::error::NONE;
} }
@ -432,14 +408,8 @@ osd_file::error osd_get_full_path(std::string &dst, std::string const &path)
bool osd_is_absolute_path(std::string const &path) bool osd_is_absolute_path(std::string const &path)
{ {
bool result = false; auto t_path = tstring_from_utf8(path.c_str());
TCHAR *t_path = tstring_from_utf8(path.c_str()); return !PathIsRelative(t_path.c_str());
if (t_path != nullptr)
{
result = !PathIsRelative(t_path);
osd_free(t_path);
}
return result;
} }

View File

@ -87,12 +87,9 @@ bool win_check_ptty_path(std::string const &path)
osd_file::error win_open_ptty(std::string const &path, std::uint32_t openflags, osd_file::ptr &file, std::uint64_t &filesize) osd_file::error win_open_ptty(std::string const &path, std::uint32_t openflags, osd_file::ptr &file, std::uint64_t &filesize)
{ {
TCHAR *t_name = tstring_from_utf8(path.c_str()); auto t_name = tstring_from_utf8(path.c_str());
if (!t_name)
return osd_file::error::OUT_OF_MEMORY;
HANDLE pipe = CreateNamedPipe(t_name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 1, 32, 32, 0, nullptr); HANDLE pipe = CreateNamedPipe(t_name.c_str(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 1, 32, 32, 0, nullptr);
osd_free(t_name);
if (INVALID_HANDLE_VALUE == pipe) if (INVALID_HANDLE_VALUE == pipe)
return osd_file::error::ACCESS_DENIED; return osd_file::error::ACCESS_DENIED;

View File

@ -85,10 +85,9 @@ bool osd_font_windows::open(std::string const &font_path, std::string const &_na
logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
// copy in the face name // copy in the face name
TCHAR *face = tstring_from_utf8(name.c_str()); std::basic_string<TCHAR> face = tstring_from_utf8(name.c_str());
_tcsncpy(logfont.lfFaceName, face, sizeof(logfont.lfFaceName) / sizeof(TCHAR)); _tcsncpy(logfont.lfFaceName, face.c_str(), sizeof(logfont.lfFaceName) / sizeof(TCHAR));
logfont.lfFaceName[sizeof(logfont.lfFaceName) / sizeof(TCHAR)-1] = 0; logfont.lfFaceName[sizeof(logfont.lfFaceName) / sizeof(TCHAR)-1] = 0;
osd_free(face);
// create the font // create the font
height = logfont.lfHeight; height = logfont.lfHeight;
@ -111,9 +110,8 @@ bool osd_font_windows::open(std::string const &font_path, std::string const &_na
} }
// if it doesn't match our request, fail // if it doesn't match our request, fail
char *utf = utf8_from_tstring(&realname[0]); std::string utf = utf8_from_tstring(&realname[0]);
int result = core_stricmp(utf, name.c_str()); int result = core_stricmp(utf.c_str(), name.c_str());
osd_free(utf);
// if we didn't match, nuke our font and fall back // if we didn't match, nuke our font and fall back
if (result != 0) if (result != 0)
@ -301,9 +299,8 @@ private:
static int CALLBACK font_family_callback(LOGFONT const *lpelfe, TEXTMETRIC const *lpntme, DWORD FontType, LPARAM lParam) static int CALLBACK font_family_callback(LOGFONT const *lpelfe, TEXTMETRIC const *lpntme, DWORD FontType, LPARAM lParam)
{ {
auto &result = *reinterpret_cast<std::vector<std::pair<std::string, std::string> > *>(lParam); auto &result = *reinterpret_cast<std::vector<std::pair<std::string, std::string> > *>(lParam);
char *face = utf8_from_tstring(lpelfe->lfFaceName); std::string face = utf8_from_tstring(lpelfe->lfFaceName);
if ((*face != '@') && (result.empty() || (result.back().first != face))) result.emplace_back(face, face); if ((face[0] != '@') && (result.empty() || (result.back().first != face))) result.emplace_back(face, face);
osd_free(face);
return TRUE; return TRUE;
} }
}; };

View File

@ -260,29 +260,18 @@ public:
return std::string(defstring); return std::string(defstring);
} }
auto osd_free_deleter = [](char *p) { osd_free(p); };
// convert the name to utf8 // convert the name to utf8
auto namestring = std::unique_ptr<char, decltype(osd_free_deleter)>(utf8_from_tstring(instance.tszName), osd_free_deleter); std::string namestring = utf8_from_tstring(instance.tszName);
// if no suffix, return as-is // if no suffix, return as-is
if (suffix == nullptr) if (suffix == nullptr)
{ return namestring;
return std::string(namestring.get());
}
// otherwise, allocate space to add the suffix
auto combined = std::make_unique<char[]>(strlen(namestring.get()) + 1 + _tcslen(suffix) + 1);
// convert the suffix to utf8 // convert the suffix to utf8
auto suffix_utf8 = std::unique_ptr<char, decltype(osd_free_deleter)>(utf8_from_tstring(suffix), osd_free_deleter); std::string suffix_utf8 = utf8_from_tstring(suffix);
// Concat the name and suffix // Concat the name and suffix
strcpy(combined.get(), namestring.get()); return namestring + " " + suffix_utf8;
strcat(combined.get(), " ");
strcat(combined.get(), suffix_utf8.get());
return std::string(combined.get());
} }
protected: protected:

View File

@ -79,11 +79,10 @@ public:
HRESULT result; HRESULT result;
// convert instance name to utf8 // convert instance name to utf8
auto osd_deleter = [](void *ptr) { osd_free(ptr); }; std::string utf8_instance_name = utf8_from_tstring(instance->tszInstanceName);
auto utf8_instance_name = std::unique_ptr<char, decltype(osd_deleter)>(utf8_from_tstring(instance->tszInstanceName), osd_deleter);
// allocate memory for the device object // allocate memory for the device object
TDevice* devinfo = module.devicelist()->create_device<TDevice>(machine, utf8_instance_name.get(), module); TDevice* devinfo = module.devicelist()->create_device<TDevice>(machine, utf8_instance_name.c_str(), module);
// attempt to create a device // attempt to create a device
result = m_dinput->CreateDevice(instance->guidInstance, devinfo->dinput.device.GetAddressOf(), nullptr); result = m_dinput->CreateDevice(instance->guidInstance, devinfo->dinput.device.GetAddressOf(), nullptr);

View File

@ -507,10 +507,9 @@ protected:
std::wstring name = rawinput_device_improve_name(tname.get()); std::wstring name = rawinput_device_improve_name(tname.get());
// convert name to utf8 // convert name to utf8
auto osd_deleter = [](void *ptr) { osd_free(ptr); }; std::string utf8_name = utf8_from_wstring(name.c_str());
auto utf8_name = std::unique_ptr<char, decltype(osd_deleter)>(utf8_from_wstring(name.c_str()), osd_deleter);
devinfo = devicelist()->create_device<TDevice>(machine, utf8_name.get(), *this); devinfo = devicelist()->create_device<TDevice>(machine, utf8_name.c_str(), *this);
// Add the handle // Add the handle
devinfo->set_handle(rawinputdevice->hDevice); devinfo->set_handle(rawinputdevice->hDevice);
@ -609,16 +608,14 @@ protected:
{ {
input_item_id itemid = table.map_di_scancode_to_itemid(keynum); input_item_id itemid = table.map_di_scancode_to_itemid(keynum);
TCHAR keyname[100]; TCHAR keyname[100];
char *name;
// generate the name // generate the name
if (GetKeyNameText(((keynum & 0x7f) << 16) | ((keynum & 0x80) << 17), keyname, ARRAY_LENGTH(keyname)) == 0) if (GetKeyNameText(((keynum & 0x7f) << 16) | ((keynum & 0x80) << 17), keyname, ARRAY_LENGTH(keyname)) == 0)
_sntprintf(keyname, ARRAY_LENGTH(keyname), TEXT("Scan%03d"), keynum); _sntprintf(keyname, ARRAY_LENGTH(keyname), TEXT("Scan%03d"), keynum);
name = utf8_from_tstring(keyname); std::string name = utf8_from_tstring(keyname);
// add the item to the device // add the item to the device
devinfo->device()->add_item(name, itemid, generic_button_get_state<std::uint8_t>, &devinfo->keyboard.state[keynum]); devinfo->device()->add_item(name.c_str(), itemid, generic_button_get_state<std::uint8_t>, &devinfo->keyboard.state[keynum]);
osd_free(name);
} }
} }
}; };

View File

@ -251,7 +251,7 @@ void osd_break_into_debugger(const char *message)
// get_clipboard_text_by_format // get_clipboard_text_by_format
//============================================================ //============================================================
static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID data)) static char *get_clipboard_text_by_format(UINT format, std::string (*convert)(LPCVOID data))
{ {
char *result = nullptr; char *result = nullptr;
HANDLE data_handle; HANDLE data_handle;
@ -272,7 +272,12 @@ static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID
if (data != nullptr) if (data != nullptr)
{ {
// invoke the convert // invoke the convert
result = (*convert)(data); std::string s = (*convert)(data);
// copy the string
result = (char *) osd_malloc(s.size() + 1);
if (result != nullptr)
memcpy(result, s.data(), s.size() * sizeof(*result));
// unlock the data // unlock the data
GlobalUnlock(data_handle); GlobalUnlock(data_handle);
@ -290,7 +295,7 @@ static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID
// convert_wide // convert_wide
//============================================================ //============================================================
static char *convert_wide(LPCVOID data) static std::string convert_wide(LPCVOID data)
{ {
return utf8_from_wstring((LPCWSTR) data); return utf8_from_wstring((LPCWSTR) data);
} }
@ -299,7 +304,7 @@ static char *convert_wide(LPCVOID data)
// convert_ansi // convert_ansi
//============================================================ //============================================================
static char *convert_ansi(LPCVOID data) static std::string convert_ansi(LPCVOID data)
{ {
return utf8_from_astring((LPCSTR) data); return utf8_from_astring((LPCSTR) data);
} }
@ -362,13 +367,8 @@ protected:
for (auto const &library : m_libraries) for (auto const &library : m_libraries)
{ {
TCHAR *tempstr = tstring_from_utf8(library.c_str()); auto tempstr = tstring_from_utf8(library.c_str());
if (!tempstr) HMODULE module = load_library(tempstr.c_str());
return nullptr;
HMODULE module = load_library(tempstr);
osd_free(tempstr);
if (module != nullptr) if (module != nullptr)
{ {

View File

@ -2569,9 +2569,9 @@ effect::effect(shaders *shadersys, IDirect3DDevice9 *dev, const char *name, cons
char name_cstr[1024]; char name_cstr[1024];
sprintf(name_cstr, "%s\\%s", path, name); sprintf(name_cstr, "%s\\%s", path, name);
TCHAR *effect_name = tstring_from_utf8(name_cstr); auto effect_name = tstring_from_utf8(name_cstr);
HRESULT hr = (*shadersys->d3dx_create_effect_from_file_ptr)(dev, effect_name, nullptr, nullptr, 0, nullptr, &m_effect, &buffer_errors); HRESULT hr = (*shadersys->d3dx_create_effect_from_file_ptr)(dev, effect_name.c_str(), nullptr, nullptr, 0, nullptr, &m_effect, &buffer_errors);
if (FAILED(hr)) if (FAILED(hr))
{ {
if (buffer_errors != nullptr) if (buffer_errors != nullptr)
@ -2588,8 +2588,6 @@ effect::effect(shaders *shadersys, IDirect3DDevice9 *dev, const char *name, cons
{ {
m_valid = true; m_valid = true;
} }
osd_free(effect_name);
} }
effect::~effect() effect::~effect()

View File

@ -2,7 +2,7 @@
// copyright-holders:Aaron Giles // copyright-holders:Aaron Giles
//============================================================ //============================================================
// //
// strconv.c - Win32 string conversion // strconv.cpp - Win32 string conversion
// //
//============================================================ //============================================================
@ -19,23 +19,28 @@
// astring_from_utf8 // astring_from_utf8
//============================================================ //============================================================
CHAR *astring_from_utf8(const char *utf8string) std::string &astring_from_utf8(std::string &dst, const char *s)
{ {
WCHAR *wstring;
int char_count;
CHAR *result;
// convert MAME string (UTF-8) to UTF-16 // convert MAME string (UTF-8) to UTF-16
char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, nullptr, 0); std::basic_string<WCHAR> wstring = wstring_from_utf8(s);
wstring = (WCHAR *)alloca(char_count * sizeof(*wstring));
MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, wstring, char_count);
// convert UTF-16 to "ANSI code page" string // convert UTF-16 to "ANSI code page" string
char_count = WideCharToMultiByte(CP_ACP, 0, wstring, -1, nullptr, 0, nullptr, nullptr); int char_count = WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), -1, nullptr, 0, nullptr, nullptr);
result = (CHAR *)osd_malloc_array(char_count * sizeof(*result)); dst.resize(char_count - 1);
if (result != nullptr) WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), -1, &dst[0], char_count - 1, nullptr, nullptr);
WideCharToMultiByte(CP_ACP, 0, wstring, -1, result, char_count, nullptr, nullptr);
return dst;
}
//============================================================
// astring_from_utf8
//============================================================
std::string astring_from_utf8(const char *s)
{
std::string result;
astring_from_utf8(result, s);
return result; return result;
} }
@ -44,23 +49,26 @@ CHAR *astring_from_utf8(const char *utf8string)
// utf8_from_astring // utf8_from_astring
//============================================================ //============================================================
char *utf8_from_astring(const CHAR *astring) std::string &utf8_from_astring(std::string &dst, const CHAR *s)
{ {
WCHAR *wstring;
int char_count;
CHAR *result;
// convert "ANSI code page" string to UTF-16 // convert "ANSI code page" string to UTF-16
char_count = MultiByteToWideChar(CP_ACP, 0, astring, -1, nullptr, 0); int char_count = MultiByteToWideChar(CP_ACP, 0, s, -1, nullptr, 0);
wstring = (WCHAR *)alloca(char_count * sizeof(*wstring)); std::wstring wstring(char_count - 1, 0);
MultiByteToWideChar(CP_ACP, 0, astring, -1, wstring, char_count); MultiByteToWideChar(CP_ACP, 0, s, -1, &wstring[0], char_count - 1);
// convert UTF-16 to MAME string (UTF-8) // convert UTF-16 to MAME string (UTF-8)
char_count = WideCharToMultiByte(CP_UTF8, 0, wstring, -1, nullptr, 0, nullptr, nullptr); return utf8_from_wstring(dst, wstring.c_str());
result = (CHAR *)osd_malloc_array(char_count * sizeof(*result)); }
if (result != nullptr)
WideCharToMultiByte(CP_UTF8, 0, wstring, -1, result, char_count, nullptr, nullptr);
//============================================================
// utf8_from_astring
//============================================================
std::string utf8_from_astring(const CHAR *s)
{
std::string result;
utf8_from_astring(result, s);
return result; return result;
} }
@ -69,17 +77,25 @@ char *utf8_from_astring(const CHAR *astring)
// wstring_from_utf8 // wstring_from_utf8
//============================================================ //============================================================
WCHAR *wstring_from_utf8(const char *utf8string) std::wstring &wstring_from_utf8(std::wstring &dst, const char *s)
{ {
int char_count;
WCHAR *result;
// convert MAME string (UTF-8) to UTF-16 // convert MAME string (UTF-8) to UTF-16
char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, nullptr, 0); int char_count = MultiByteToWideChar(CP_UTF8, 0, s, -1, nullptr, 0);
result = (WCHAR *)osd_malloc_array(char_count * sizeof(*result)); dst.resize(char_count - 1);
if (result != nullptr) MultiByteToWideChar(CP_UTF8, 0, s, -1, &dst[0], char_count - 1);
MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count);
return dst;
}
//============================================================
// wstring_from_utf8
//============================================================
std::wstring wstring_from_utf8(const char *s)
{
std::wstring result;
wstring_from_utf8(result, s);
return result; return result;
} }
@ -88,20 +104,29 @@ WCHAR *wstring_from_utf8(const char *utf8string)
// utf8_from_wstring // utf8_from_wstring
//============================================================ //============================================================
char *utf8_from_wstring(const WCHAR *wstring) std::string &utf8_from_wstring(std::string &dst, const WCHAR *s)
{ {
int char_count;
char *result;
// convert UTF-16 to MAME string (UTF-8) // convert UTF-16 to MAME string (UTF-8)
char_count = WideCharToMultiByte(CP_UTF8, 0, wstring, -1, nullptr, 0, nullptr, nullptr); int char_count = WideCharToMultiByte(CP_UTF8, 0, s, -1, nullptr, 0, nullptr, nullptr);
result = (char *)osd_malloc_array(char_count * sizeof(*result)); dst.resize(char_count - 1);
if (result != nullptr) WideCharToMultiByte(CP_UTF8, 0, s, -1, &dst[0], char_count - 1, nullptr, nullptr);
WideCharToMultiByte(CP_UTF8, 0, wstring, -1, result, char_count, nullptr, nullptr);
return dst;
}
//============================================================
// utf8_from_wstring
//============================================================
std::string utf8_from_wstring(const WCHAR *s)
{
std::string result;
utf8_from_wstring(result, s);
return result; return result;
} }
//============================================================ //============================================================
// osd_uchar_from_osdchar // osd_uchar_from_osdchar
//============================================================ //============================================================

View File

@ -27,32 +27,15 @@
// the result of these functions has to be released with osd_free() // the result of these functions has to be released with osd_free()
CHAR *astring_from_utf8(const char *s); std::string astring_from_utf8(const char *s);
char *utf8_from_astring(const CHAR *s); std::string &astring_from_utf8(std::string &dst, const char *s);
std::string utf8_from_astring(const CHAR *s);
std::string &utf8_from_astring(std::string &dst, const CHAR *s);
WCHAR *wstring_from_utf8(const char *s); std::wstring wstring_from_utf8(const char *s);
char *utf8_from_wstring(const WCHAR *s); std::wstring &wstring_from_utf8(std::wstring &dst, const char *s);
std::string utf8_from_wstring(const WCHAR *s);
struct osd_wstr_deleter std::string &utf8_from_wstring(std::string &dst, const WCHAR *s);
{
void operator () (wchar_t* wstr) const
{
if (wstr != nullptr)
osd_free(wstr);
}
};
struct osd_str_deleter
{
void operator () (char* str) const
{
if (str != nullptr)
osd_free(str);
}
};
typedef std::unique_ptr<wchar_t, osd_wstr_deleter> osd_unique_wstr;
typedef std::unique_ptr<char, osd_str_deleter> osd_unique_str;
#ifdef UNICODE #ifdef UNICODE
#define tstring_from_utf8 wstring_from_utf8 #define tstring_from_utf8 wstring_from_utf8

View File

@ -14,6 +14,8 @@
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
#include <stdlib.h> #include <stdlib.h>
#include <vector>
#include <string>
#include "strconv.h" #include "strconv.h"
@ -27,29 +29,19 @@ extern int utf8_main(int argc, char *argv[]);
#ifdef UNICODE #ifdef UNICODE
extern "C" int _tmain(int argc, TCHAR **argv) extern "C" int _tmain(int argc, TCHAR **argv)
{ {
int i, rc; int i;
char **utf8_argv; std::vector<std::string> argv_vectors(argc);
char **utf8_argv = (char **) alloca(argc * sizeof(char *));
/* convert arguments to UTF-8 */ // convert arguments to UTF-8
utf8_argv = (char **) malloc(argc * sizeof(*argv));
if (utf8_argv == nullptr)
return 999;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
utf8_argv[i] = utf8_from_tstring(argv[i]); argv_vectors[i] = utf8_from_tstring(argv[i]);
if (utf8_argv[i] == nullptr) utf8_argv[i] = (char *) argv_vectors[i].c_str();
return 999;
} }
/* run utf8_main */ // run utf8_main
rc = utf8_main(argc, utf8_argv); return utf8_main(argc, utf8_argv);
/* free arguments */
for (i = 0; i < argc; i++)
osd_free(utf8_argv[i]);
free(utf8_argv);
return rc;
} }
#endif #endif

View File

@ -125,9 +125,7 @@ void win_monitor_info::refresh()
result = GetMonitorInfo(m_handle, static_cast<LPMONITORINFO>(&m_info)); result = GetMonitorInfo(m_handle, static_cast<LPMONITORINFO>(&m_info));
assert(result); assert(result);
osd_unique_str temp(utf8_from_tstring(m_info.szDevice)); m_name = utf8_from_tstring(m_info.szDevice);
if (temp) m_name.assign(temp.get());
m_pos_size = RECT_to_osd_rect(m_info.rcMonitor); m_pos_size = RECT_to_osd_rect(m_info.rcMonitor);
m_usuable_pos_size = RECT_to_osd_rect(m_info.rcWork); m_usuable_pos_size = RECT_to_osd_rect(m_info.rcWork);
@ -202,10 +200,10 @@ BOOL CALLBACK win_monitor_info::monitor_enum_callback(HMONITOR handle, HDC dc, L
float aspect = static_cast<float>(info.rcMonitor.right - info.rcMonitor.left) / static_cast<float>(info.rcMonitor.bottom - info.rcMonitor.top); float aspect = static_cast<float>(info.rcMonitor.right - info.rcMonitor.left) / static_cast<float>(info.rcMonitor.bottom - info.rcMonitor.top);
// allocate a new monitor info // allocate a new monitor info
osd_unique_str temp(utf8_from_tstring(info.szDevice)); auto temp = utf8_from_tstring(info.szDevice);
// copy in the data // copy in the data
auto monitor = std::make_shared<win_monitor_info>(handle, temp.get(), aspect); auto monitor = std::make_shared<win_monitor_info>(handle, temp.c_str(), aspect);
// hook us into the list // hook us into the list
osd_monitor_info::list.push_back(monitor); osd_monitor_info::list.push_back(monitor);

View File

@ -23,12 +23,8 @@
void win_output_debug_string_utf8(const char *string) void win_output_debug_string_utf8(const char *string)
{ {
TCHAR *t_string = tstring_from_utf8(string); auto t_string = tstring_from_utf8(string);
if (t_string != nullptr) OutputDebugString(t_string.c_str());
{
OutputDebugString(t_string);
osd_free(t_string);
}
} }
@ -39,32 +35,24 @@ void win_output_debug_string_utf8(const char *string)
int win_message_box_utf8(HWND window, const char *text, const char *caption, UINT type) int win_message_box_utf8(HWND window, const char *text, const char *caption, UINT type)
{ {
int result = IDNO; LPCTSTR t_text = nullptr;
TCHAR *t_text = nullptr; LPCTSTR t_caption = nullptr;
TCHAR *t_caption = nullptr; std::basic_string<TCHAR> ts_text;
std::basic_string<TCHAR> ts_caption;
if (text) if (text)
{ {
t_text = tstring_from_utf8(text); ts_text = tstring_from_utf8(text);
if (!t_text) t_text = ts_text.c_str();
goto done;
} }
if (caption) if (caption)
{ {
t_caption = tstring_from_utf8(caption); ts_caption = tstring_from_utf8(caption);
if (!t_caption) t_caption = ts_caption.c_str();
goto done;
} }
result = MessageBox(window, t_text, t_caption, type); return MessageBox(window, t_text, t_caption, type);
done:
if (t_text)
osd_free(t_text);
if (t_caption)
osd_free(t_caption);
return result;
} }
@ -76,13 +64,13 @@ done:
BOOL win_set_window_text_utf8(HWND window, const char *text) BOOL win_set_window_text_utf8(HWND window, const char *text)
{ {
BOOL result = FALSE; BOOL result = FALSE;
TCHAR *t_text = nullptr; LPCTSTR t_text = nullptr;
std::basic_string<TCHAR> ts_text;
if (text) if (text)
{ {
t_text = tstring_from_utf8(text); ts_text = tstring_from_utf8(text);
if (!t_text) t_text = ts_text.c_str();
goto done;
} }
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
@ -92,9 +80,6 @@ BOOL win_set_window_text_utf8(HWND window, const char *text)
result = TRUE; result = TRUE;
#endif #endif
done:
if (t_text)
osd_free(t_text);
return result; return result;
} }
@ -107,7 +92,6 @@ done:
int win_get_window_text_utf8(HWND window, char *buffer, size_t buffer_size) int win_get_window_text_utf8(HWND window, char *buffer, size_t buffer_size)
{ {
int result = 0; int result = 0;
char *utf8_buffer = nullptr;
TCHAR t_buffer[256]; TCHAR t_buffer[256];
t_buffer[0] = '\0'; t_buffer[0] = '\0';
@ -120,15 +104,10 @@ int win_get_window_text_utf8(HWND window, char *buffer, size_t buffer_size)
wcsncpy(t_buffer, title->Data(), ARRAY_LENGTH(t_buffer)); wcsncpy(t_buffer, title->Data(), ARRAY_LENGTH(t_buffer));
#endif #endif
utf8_buffer = utf8_from_tstring(t_buffer); std::string utf8_buffer = utf8_from_tstring(t_buffer);
if (!utf8_buffer)
goto done;
result = snprintf(buffer, buffer_size, "%s", utf8_buffer); result = snprintf(buffer, buffer_size, "%s", utf8_buffer.c_str());
done:
if (utf8_buffer)
osd_free(utf8_buffer);
return result; return result;
} }
@ -142,28 +121,16 @@ HWND win_create_window_ex_utf8(DWORD exstyle, const char* classname, const char*
int x, int y, int width, int height, HWND parent, HMENU menu, int x, int y, int width, int height, HWND parent, HMENU menu,
HINSTANCE instance, void* param) HINSTANCE instance, void* param)
{ {
TCHAR* t_classname; std::basic_string<TCHAR> ts_classname = tstring_from_utf8(classname);
TCHAR* t_windowname = nullptr;
HWND result = nullptr;
t_classname = tstring_from_utf8(classname); LPCTSTR t_windowname = nullptr;
if( !t_classname ) std::basic_string<TCHAR> ts_windowname;
return result; if (windowname != nullptr)
{
if( windowname ) { ts_windowname = tstring_from_utf8(windowname);
t_windowname = tstring_from_utf8(windowname); t_windowname = ts_windowname.c_str();
if( !t_windowname ) {
osd_free(t_classname);
return result;
}
} }
result = CreateWindowEx(exstyle, t_classname, t_windowname, style, x, y, width, height, parent, return CreateWindowEx(exstyle, ts_classname.c_str(), t_windowname, style, x, y, width, height, parent,
menu, instance, param); menu, instance, param);
if( t_windowname )
osd_free(t_windowname);
osd_free(t_classname);
return result;
} }

View File

@ -106,12 +106,9 @@ void osd_subst_env(std::string &dst, const std::string &src)
{ {
TCHAR buffer[MAX_PATH]; TCHAR buffer[MAX_PATH];
TCHAR *t_src = tstring_from_utf8(src.c_str()); auto t_src = tstring_from_utf8(src.c_str());
ExpandEnvironmentStrings(t_src, buffer, ARRAY_LENGTH(buffer)); ExpandEnvironmentStrings(t_src.c_str(), buffer, ARRAY_LENGTH(buffer));
osd_free(t_src); utf8_from_tstring(dst, buffer);
char *cnv = utf8_from_tstring(buffer);
dst = cnv;
osd_free(cnv);
} }
//------------------------------------------------- //-------------------------------------------------