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
Solved

real time clock in VC++

Posted on 1997-06-11
2
851 Views
Last Modified: 2013-12-04
Hi,

Hi,

I want to write a program in Visual C++ 5.0 using MFC, which uses some kind of "real time clock".

Ok, when the program starts, the clock should start with time unit 0. Then it should count the time units in 1/10 of a second.

From my experiences with Java, I thought about using a thread, in which the clock will run. It should only count the time units and return the current, when asked for.
The main thread would then do the main work and whenever something new must be done, it should call the clock to ask for the "time". If the time is right, the next thing can be done.

Another idea is to use the function "_ftime" which returns the current time, I guess. The problem then can be the necessary calculation to do to translate the time struct to the appropriate time units. I think, this needs too much time.

It would be nice, if you could tell me which way would be the easiest(using threads, _ftime or another). It would be fine too, if you could give an example by including some example source code.

Thanks in advance, re.
0
Comment
Question by:re
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1398168
I think the easiest way is to call Win32 Multimedia function timeGetTime(). The timeGetTime function retrieves the system time, in milliseconds. The system time is the time elapsed since Windows was started. Its default precision is enough for your case. When your program starts, call timeGetTime() to record the starting time
m_dwStart = ::timeGetTime();

When you need the current time unit, do the following
DWORD dwUnit = (::timeGetTime() - m_dwStart) / 100;

0
 

Author Comment

by:re
ID: 1398169
I checked the function "timeGetTime" in a small console application and it seems to run fast enough, for what I have to do.

Thanks for your help again, re.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Table Size and Indexes in SQL Server 6 26
How to create a log table of all deleted records Sql Server 2008? 5 72
Example of WebAPI 7 33
Please explain purpose of GZIP 4 34
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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