2015-11-19 127 views
0

我使用theApp.GetSectionString(lpszSubSection, lpszEntry, lpszDefault)来从注册表中读取值。BUG:theApp.GetSectionString()不返回默认值

问题是如果注册表中缺少目标条目,它不会返回默认值。

CString str = GetSectionString(_T("Settings"),_T("Gugus"),_T("default 123"));

我也总是检查str,如果它是一个空字符串,然后手动将其设置为默认值的str

这是一个错误或默认行为GetSectionString()

CString str = theApp.GetSectionString (_T("Xenax"),_T("MechanicalLimit X-,X+,-Y-,Y+"), "-20999, 4799, 2699, -9999"); 
    if (str.empty()) // <- Needed, :(( 
    { 
     str = "-20999, 4799, 2699, -9999" ; 
    } 
+1

“CWinAppEx :: GetSectionString()”中存在一个错误。这个bug在VS 2012中修复 –

+0

是的,我正在使用VS2010。 VS2010中有这个问题的解决方法吗? –

+0

您必须更新到VS 2012或更高版本的VS或使用该解决方法。 –

回答

0

我假设你的代码应该阅读(IsEmpty()应该用来代替empty()):

CString str = theApp.GetSectionString (_T("Xenax"),_T("MechanicalLimit X-,X+,-Y-,Y+"), _T("-20999, 4799, 2699, -9999")); 
if (str.IsEmpty()) // <- Needed, :(( 
{ 
    str = _T("-20999, 4799, 2699, -9999"); 
} 

有在CWinAppEx::GetSectionString()的错误。此错误已在VS 2012中修复。更多信息在:http://blogs.msdn.com/b/vcblog/archive/2012/06/14/10320171.aspx

+0

是的,我看到 BOOL CSettingsStore ::阅读(LPCTSTR lpszValueName,CString的strValue的)问题 我不知道,如果这是一个错误或默认行为,因为同样的问题theApp.GetString(..) –