Solved

ULARGE_INTEGER

Posted on 2000-03-02
6
1,280 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Standards for file storage. 3 25
Enable Clear Text in Win 8.1 7 44
Explain Unit of Work pattern 2 63
Licensing Sharepoint 2016 for developers 11 47
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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