我有一种CString格式,会导致SDK文件输出中的32位Unicode MFC静态/ VS2013项目崩溃。c第1629行while (i-- && *pwch)
bool MyClass::Function1(LPCTSTR sAppName, HKEY hKey, LPCTSTR tcszValue1, LPCTSTR tcszValue2, LPCTSTR tcszValue3, BOOL bValue)
{
__int64 nAppId=0;
__int64 nId2=0;
sSql.Format(_T("INSERT INTO Table (AppId, Id2, RegPath, RegKey, RegValueName,
bRecurseDelete, RemoveIt) VALUES ('%d', '%d', '%s', '%s', '%s', '%d', 1)"),
nAppId, nId2, tcszValue1, tcszValue2, tcszValue3, bValue);
}
当我在64位上编译它时,它没有任何问题;在32位上,当sValue3为空时,它崩溃了(但不是第一次,当sValue为空时,对CString.Format的第4次调用)
最佳答案
您必须使用%lld
格式说明符而不是%d
说明符。
在32位世界中,%d
期望使用32位整数。但是,您提供64位整数作为参数。因此,您会得到未定义的行为,因为Format
将完全混合参数。
关于c++ - CString.Format在32位崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32096397/