Menu

Possible mismatch with UNICODE define and TCHAR in Workbook.cpp

2014-10-28
2016-02-05
  • Kelton Stefan

    Kelton Stefan - 2014-10-28

    In lines 1007 through 1013, there appears to be a discrepancy, when _UNICODE is defined, szCurrency is a wchar_t, but then if UNICODE is defined at the same time, then the function "wcstombs" chokes on szCurrency because it is a wchar_t not char as it expects. It seems that it should actually use the "_stprintf" on line 1013 instead.

    When I try to compile as is (with UNICODE and _UNICODE defined), I get the following error:
    C:\Users\kelton_stefan\Documents\Projects\foresite_c3\software\pc\c3\SimpleXlsx\Xlsx\Workbook.cpp|1010|error: cannot convert 'TCHAR {aka wchar_t}' to 'char' for argument '1' to 'size_t wcstombs(char, const wchar_t*, size_t)'|

    After changing "#ifdef UNICODE" on line 1009 to "#ifndef UNICODE", it compiles perfectly.

    I'm compiling with MinGW 4.7.1. Am I missing something here, or is this an error in the code? Thanks much, you've done a great job on this library!

    Sincerely,
    Kelton

     
  • Pavel Akimov

    Pavel Akimov - 2014-11-03

    Hi!

    This is a known issue, that the library is not ready to use with unicode indeed.
    So far, I can only recommend to switch it off (may be locally).

    Still, if you need a unicode version, take a look at Cells with russian text topic in forum, there are some links which might be helpful.

     
  • FinnG

    FinnG - 2016-02-05

    SimpleXlsx r0.20
    Workbook.cpp, line1007~1015

        string char_currency = use_facet<moneypunct<char> >(loc).curr_symbol();
        TCHAR szCurrency[10] = { 0 };
    #ifdef UNICODE
        int32_t res = wcstombs(szCurrency, char_currency.c_str(), sizeof(szCurrency));
        if (res == -1) return _T("");
    #else
        _stprintf(szCurrency, _T("%s"), char_currency.c_str());
    #endif
        _tstring currency = _tstring(_T("&quot;")) + szCurrency + _T("&quot;");
    

    Replace above with below
    (more correctly i think)

        _tstring char_currency = use_facet<moneypunct<TCHAR> >(loc).curr_symbol();
        _tstring currency = _T("&quot;") + char_currency + _T("&quot;");
    
     

Log in to post a comment.