Hi, we have the following problem:
We have a code that uses the "GetTickCount" method (the return value is the number of milliseconds that have elapsed since the system was started).
The Problem:
Since GetTickCount returns only a 32-bit number, after about 49 days, the counter wraps.
The solution we thoung is the following:
Use the "COleDateTime::GetCurrentTime", but the problem is that this method returns the value for example like: 9411.22222 (double variable)
and we need the value in DWORD so when we set the value in the variable we lost all the date after the '.', we will receive the value "9411".
Any Ideas?
How to resolve this?
Thanks :eek:

Recommended Answers

All 4 Replies

You could set up another variable that increments each time your value wraps. That effectively gives you a 64bit counter. This of course would require some minor redesign every time your counter is accessed in the code.

Would it be ok for you if you used an external time library. If yes then you can try out C++ Boost Date time library:

Thanks for the qick answers:
1. We prefer not use external libraries, but thanks
2. What do you mean "This of course would require some minor redesign every time your counter is accessed in the code"?
Thanks again

What do you mean "This of course would require some minor redesign every time your counter is accessed in the code"?

I think what Mr. WaltP means is that when you have to get the actual value of the counter you have to take into consideration the current "counter" value as well as the "number_of_times_counter_overflowed".

For eg.
If current counter value = 12324 and it has already overflowed 2 times then the actual counter value can be obtained by:

actual_counter = counter + overflow_times * MAX_COUNTER_VALUE ;

But its just what i think, for the actual theory you will have to wait till he again comes online :D

Hope it helped, bye.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.