gpt4 book ai didi

c++ - CString.Format 在 32 位中崩溃

转载 作者:行者123 更新时间:2023-11-30 02:37:00 25 4
gpt4 key购买 nike

我有一个 CString 格式导致 32 位 Unicode MFC 静态/VS2013 项目在 SDK 文件 output.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 为空时崩溃(但不是第一次,在第 4 次调用 CString.Format 时当 sValue 为空时)

最佳答案

您必须使用 %lld 格式说明符而不是 %d 说明符。

在 32 位世界中,%d 需要一个 32 位整数。但是您提供 64 位整数作为参数。因此你会得到未定义的行为,因为 Format 会完全混淆参数。

关于c++ - CString.Format 在 32 位中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32096397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com