简体   繁体   English

C ++-全局setlocale有效,传递给_vsnprintf_l的相同语言环境不起作用

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

I have following C++ code sample: 我有以下C ++代码示例:

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 = ::_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. arglist包含具有扩展ascii字符的LPCTSTR。 Command //1 copies it to the buffer, as expected. 命令// 1将其复制到缓冲区,如预期的那样。 Command //2 stops copying at first character from range 129-161 (few exceptions there). 命令// 2停止复制范围129-161中的第一个字符(那里很少有例外)。

I'd like to address this issue without changing global locale for process, but command //3 works like //2, why? 我想在不更改进程的全局语言环境的情况下解决此问题,但是命令// 3的作用类似于// 2,为什么? I'm passing "C" locale, so I would expect effect from command //1. 我正在传递“ C”语言环境,所以我期望从命令// 1生效。

By default I'm using Polish locale on english Windows XP. 默认情况下,我在英语Windows XP上使用波兰语区域设置。

It turned out to be a CRT bug in VS2005 and above (2008 and 2010). 事实证明,这是VS2005及更高版本(2008和2010)中的CRT错误。 Submitted to Microsoft here: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=523503#details 在此处提交给Microsoft: 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. 错误适用于_sprintf_l,_vsnprintf_l,_sprintf_s_l,_vsnprintf_s_l以及其他亲戚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM