CString值在64位转换时会被截断
问题描述:
当我从Ulong64转换为cstring值时会被截断为64位,任何人都可以帮我解决这个问题吗?CString值在64位转换时会被截断
HMONITOR hmonitor64; // Hmonitor decl
hmonitor64 = (HMONITOR)0x0000000300290eaf;// initialize to big value
ULONG64 lmonitor64;
CString strMonitor64;
lmonitor64 = (ULONG64)hmonitor64; // typecasted to long
strMonitor64.Format(_T("%lu"), lmonitor64); // value gets truncated in cstring
答
格式化ULONG64
正确的方法是:
HMONITOR hmonitor64; // Hmonitor decl
hmonitor64 = (HMONITOR)0x0000000300290eaf;// initialize to big value
ULONG64 lmonitor64;
CString strMonitor64;
lmonitor64 = (ULONG64)hmonitor64; // typecasted to long
strMonitor64.Format(_T("%I64u"), lmonitor64); // value gets truncated in cstring
请格式化你的源代码。 (使用编辑器的工具按钮'{}')。 – Scheff
没有任何研究,我猜你必须使用'“%llu”'。 'long'意味着即使在64位平台上,Windows/VC也有32位。所以,你必须使用'long long unsigned'或者(像你一样)'ULONG64'。 – Scheff
截断也发生在32位代码中。你只是不会注意到,因为'HMONITOR'在32位代码中是32位宽。 – IInspectable