2017-02-16 67 views
0

當我從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 
+0

請格式化你的源代碼。 (使用編輯器的工具按鈕'{}')。 – Scheff

+2

沒有任何研究,我猜你必須使用'「%llu」'。 'long'意味着即使在64位平臺上,Windows/VC也有32位。所以,你必須使用'long long unsigned'或者(像你一樣)'ULONG64'。 – Scheff

+0

截斷也發生在32位代碼中。你只是不會注意到,因爲'HMONITOR'在32位代碼中是32位寬。 – IInspectable

回答

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