开发者

C++ - global setlocale works, the same locale passed to _vsnprintf_l doesn't

I have following C++ code sample:

void SetVaArgs(const char* fmt, const va_list argList)
{
  setlocale( LC_ALL, "C" );

  // 1
  m_FormatBufferLen = ::_vsnprintf(m_FormatBuffer, Logger::MAX_LOGMESSAGE_SIZE, fmt, argList); 

  setlocale( LC_ALL, "" );

  //2
  m_FormatBufferLen = 开发者_StackOverflow中文版::_vsnprintf(m_FormatBuffer, Logger::MAX_LOGMESSAGE_SIZE, fmt, argList);

  _locale_t locale = _create_locale(LC_ALL, "C");;

  //3
  m_FormatBufferLen = ::_vsnprintf_l(m_FormatBuffer, Logger::MAX_LOGMESSAGE_SIZE, fmt,locale, argList);

The arglist contains LPCTSTR with extended ascii characters. Command //1 copies it to the buffer, as expected. Command //2 stops copying at first character from range 129-161 (few exceptions there).

I'd like to address this issue without changing global locale for process, but command //3 works like //2, why? I'm passing "C" locale, so I would expect effect from command //1.

By default I'm using Polish locale on english Windows XP.


It turned out to be a CRT bug in VS2005 and above (2008 and 2010). Submitted to Microsoft here: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=523503#details

Bug applies to _sprintf_l, _vsnprintf_l, _sprintf_s_l, _vsnprintf_s_l and possibly other relatives.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜