Solved

ULARGE_INTEGER

Posted on 2000-03-02
6
1,269 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
ID: 2576320
   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
ID: 2576344
PS: prefix "%I64" is microsoft specific
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 100 total points
ID: 2578345
For MS VC 6.0

#include <stdio.h>

void main()
{
__int64 a = 3333333333 ;
__int64 b = 3333333333 ;
__int64 c=a+b;
printf("%I64d",c);
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:zhenteng
ID: 2578713
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
ID: 2578766
I just noticed it's caused by CString
0
 
LVL 9

Expert Comment

by:Pacman
ID: 2579364
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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

24 Experts available now in Live!

Get 1:1 Help Now