Solved

ULARGE_INTEGER

Posted on 2000-03-02
6
1,285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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