Solved

ULARGE_INTEGER

Posted on 2000-03-02
6
1,263 Views
Last Modified: 2013-12-03
if I have two unsigned long values? How can i add them up together and reflec the total in a ULARGE_INTEGER variables

unsigned long a = 3333333333
unsigned long b = 3333333333
unsigned long c = a + b
                = 6666666666 - 4294967296
                = 2371699370
If I want to print out the total value of  ULARGE_INTEGER, which is 6666666666, how should my printf statement looks like?
0
Comment
Question by:zhenteng
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Pacman
Comment Utility
   ULARGE_INTEGER abc;
    unsigned long a = 3333333333;
    unsigned long b = 3333333333;

    abc.QuadPart = a;
    abc.QuadPart += b;
    sprintf(buf, "%I64d", abc);

0
 
LVL 9

Expert Comment

by:Pacman
Comment Utility
PS: prefix "%I64" is microsoft specific
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 100 total points
Comment Utility
For MS VC 6.0

#include <stdio.h>

void main()
{
__int64 a = 3333333333 ;
__int64 b = 3333333333 ;
__int64 c=a+b;
printf("%I64d",c);
}
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:zhenteng
Comment Utility
The sprintf statement doesn't seem to work though. I traced thru the code and found this error at the line when sprintf statement took place.

Total.QuadPart = Total.QuadPart/1000/1000;
dHD = Total.LowPart;
dHD = dHD/1000;
sprintf(oTemp.GetBuffer(10), "%.2g GB", dHD);

The error I got was:
Debug Error!
Program: C:\Personal\TestProg\TestProg.exe
DAMAGE: after Normal block (#135) at 0x00DB26F0

Whether I use %.2f or %.2e or %.2g, I still got the error.

Thank You
0
 

Author Comment

by:zhenteng
Comment Utility
I just noticed it's caused by CString
0
 
LVL 9

Expert Comment

by:Pacman
Comment Utility
zhenteng,

buf is char array:

char buf[100];

I don't know CString because I don't use MFC.
If you take this buffer it will work fine.
I'm using VC5.0.

Here again the complete example.


 ULARGE_INTEGER abc;
 unsigned long a = 3333333333;
 unsigned long b = 3333333333;
 char buf[100];

 abc.QuadPart = a;
 abc.QuadPart += b;
 abc.QuadPart = abc.QuadPart / 1024 / 1024;  // ... to GB
 sprintf(buf, "%I64d", abc);


If you want you can use __int64 instead of ULARGE_INTEGER (see NickRepin's comment).
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now