diff --git a/minimp3_ex.h b/minimp3_ex.h index 2871705..e8bf445 100644 --- a/minimp3_ex.h +++ b/minimp3_ex.h @@ -1173,7 +1173,7 @@ static int mp3dec_open_file_h(HANDLE file, mp3dec_map_info_t *map_info) HANDLE mapping = NULL; LARGE_INTEGER s; - s.LowPart = GetFileSize(file, (DWORD*)&s.HighPart); + s.LowPart = GetFileSizeEx(file, &s); if (s.LowPart == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) goto error; map_info->size = s.QuadPart; @@ -1193,12 +1193,28 @@ static int mp3dec_open_file_h(HANDLE file, mp3dec_map_info_t *map_info) CloseHandle(file); return MP3D_E_IOERROR; } - +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP +#define __mp3dec_create_file(path, omode, smode, cflags) CreateFileW(path, omode, smode, nullptr, cflags, 0, nullptr) +#else +#define __mp3dec_create_file(path, omode, smode, cflags) CreateFile2(path, omode, smode, cflags, nullptr) +#endif static int mp3dec_open_file(const char *file_name, mp3dec_map_info_t *map_info) { if (!file_name) return MP3D_E_PARAM; - HANDLE file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + int cch = ::MultiByteToWideChar(CP_UTF8, 0, file_name, -1, NULL, 0); + if (cch < 2) + return MP3D_E_PARAM; + wchar_t* file_name_w = (wchar_t*)malloc(cch * sizeof(wchar_t*)); + if (!file_name_w) + return MP3D_E_MEMORY; + if (::MultiByteToWideChar(CP_UTF8, 0, file_name, cch, file_name_w, cch) != cch) + { + free(file_name_w); + return MP3D_E_PARAM; + } + HANDLE file = __mp3dec_create_file(file_name_w, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING); + free(file_name_w); if (INVALID_HANDLE_VALUE == file) return MP3D_E_IOERROR; return mp3dec_open_file_h(file, map_info); @@ -1208,7 +1224,7 @@ static int mp3dec_open_file_w(const wchar_t *file_name, mp3dec_map_info_t *map_i { if (!file_name) return MP3D_E_PARAM; - HANDLE file = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + HANDLE file = __mp3dec_create_file(file_name, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING); if (INVALID_HANDLE_VALUE == file) return MP3D_E_IOERROR; return mp3dec_open_file_h(file, map_info);