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

UTF8 file path support on Windows #91

Open
joerg-schlager opened this issue Oct 22, 2023 · 2 comments
Open

UTF8 file path support on Windows #91

joerg-schlager opened this issue Oct 22, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@joerg-schlager
Copy link

Hi,

in the default Windows configuration for 3.02a, jm_portability_load_dll_handle_with_flag(const char* dll_file_path, jm_portability_loadlibrary_flag_t flag) uses LoadLibraryEx(dll_file_path, NULL, flag); - there is thus no support for UTF8 characters in the dll_file_path, and loading DLLs from any path containing UTF8 characters subsequently fails. Is there any solution for support unicode file paths within fmilib?

@joerg-schlager
Copy link
Author

I just drafted a simple fix for this issue (see below), and it appears to be working that way, However, I'm afraid that similar code would need to be injected all over jm_portability.c to get full UTF8 support on Windows.

DLL_HANDLE jm_portability_load_dll_handle_with_flag(const char* dll_file_path, jm_portability_loadlibrary_flag_t flag)
{
#ifdef WIN32
// first, try to load using UTF16

HMODULE h_module = NULL;
int utf8_len = (int)strlen(dll_file_path);
int utf16_buffer_len =  MultiByteToWideChar(CP_UTF8, 0, dll_file_path, utf8_len, NULL, 0);
if (utf16_buffer_len > 0)
{
    wchar_t* dll_file_path_utf16 = (wchar_t*)malloc(sizeof(wchar_t) * (utf16_buffer_len+1));
    if (dll_file_path_utf16 != NULL)
    {            
        int utf16_len = MultiByteToWideChar(CP_UTF8, 0, dll_file_path, utf8_len, dll_file_path_utf16, utf16_buffer_len);
        if (utf16_len == utf16_buffer_len)
        {
            dll_file_path_utf16[utf16_buffer_len] = L'\0';
            h_module = LoadLibraryExW(dll_file_path_utf16, NULL, flag);
        }
        free(dll_file_path_utf16);            
    }
}                
return (h_module !=NULL) ? h_module : LoadLibraryExA(dll_file_path, NULL, flag);

#else
return dlopen(dll_file_path, flag);
#endif
}

@modelonrobinandersson
Copy link
Member

modelonrobinandersson commented Nov 2, 2023

Hi @joerg-schlager, thank you for highlighting this. Unfortunately we're not able to look into this at the moment but I will keep this open for future enhancements. We are currently prioritizing remaining work for support of FMI 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants