Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: fix unicode support and build errors #1423

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ option ( enable-pipewire "compile PipeWire support (if it is available)" on )
option ( enable-readline "compile readline lib line editing (if it is available)" on )
option ( enable-threads "enable multi-threading support (such as parallel voice synthesis)" on )
option ( enable-openmp "enable OpenMP support (parallelization of soundfont decoding, vectorization of voice mixing, etc.)" on )
option ( enable-unicode "enable UNICODE build for Windows" on )

# Platform specific options
if ( CMAKE_SYSTEM MATCHES "Linux" )
Expand Down Expand Up @@ -293,7 +294,9 @@ if ( WIN32 OR CYGWIN )
endif()
endif ()
message ( STATUS "Targeting Windows Version ${windows-version}" )
add_definitions ( -D _UNICODE -D UNICODE )
if ( enable-unicode )
add_definitions ( -D _UNICODE -D UNICODE )
endif ()
add_definitions ( -D _WIN32_WINNT=${windows-version} )
add_definitions ( -D WINVER=${windows-version} )
list ( APPEND CMAKE_REQUIRED_DEFINITIONS "-DWINVER=${windows-version}" )
Expand Down
5 changes: 4 additions & 1 deletion src/drivers/fluid_waveout.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,11 @@ new_fluid_waveout_audio_driver2(fluid_settings_t *settings, fluid_audio_func_t f
if(res == MMSYSERR_NOERROR)
{
#ifdef _UNICODE

#ifdef __CYGWIN__
if(wcscasecmp(lpwDevName, caps.szPname) == 0)
#else
if(wcsicmp(lpwDevName, caps.szPname) == 0)
#endif
#else
if(FLUID_STRCASECMP(dev_name, caps.szPname) == 0)
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/drivers/fluid_winmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,9 @@ fluid_winmidi_parse_device_name(fluid_winmidi_driver_t *dev, char *dev_name)
static void fluid_winmidi_autoconnect_build_name(char *name)
{
char new_name[MAXPNAMELEN] = { 0 };
int i, j, n = 0;
int num = midiInGetNumDevs();
int j;
unsigned int i, n = 0;
unsigned int num = midiInGetNumDevs();

for (i = 0; i < num; ++i)
{
Expand Down
11 changes: 8 additions & 3 deletions src/utils/fluid_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1787,9 +1787,16 @@ fluid_long_long_t fluid_file_tell(FILE* f)

#if defined(_WIN32) || defined(__CYGWIN__)
// not thread-safe!
#define FLUID_WINDOWS_MEX_ERROR_LEN 1024

char* fluid_get_windows_error(void)
{
static TCHAR err[1024];
#ifdef _UNICODE
TCHAR err[FLUID_WINDOWS_MEX_ERROR_LEN];
static char ascii_err[FLUID_WINDOWS_MEX_ERROR_LEN];
#else
static TCHAR err[FLUID_WINDOWS_MEX_ERROR_LEN];
#endif

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
Expand All @@ -1800,8 +1807,6 @@ char* fluid_get_windows_error(void)
NULL);

#ifdef _UNICODE
static char ascii_err[sizeof(err)];

WideCharToMultiByte(CP_UTF8, 0, err, -1, ascii_err, sizeof(ascii_err)/sizeof(ascii_err[0]), 0, 0);
return ascii_err;
#else
Expand Down
6 changes: 6 additions & 0 deletions src/utils/fluid_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ typedef gintptr intptr_t;
#pragma warning(disable : 4996)
#endif

/*
* Required by Windows-specific sf_wchar_open() from
* libsndfile that takes a UTF16_BE encoded filename.
*/
#define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


#endif

/* Darwin special defines (taken from config_macosx.h) */
Expand Down
Loading