在64位转换期间,CString值被截断

时间:2017-02-16 09:02:45

标签: c++ mfc

当我从Ulong64转换为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

1 个答案:

答案 0 :(得分:3)

格式化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