Solved

Using a timer in c

Posted on 2008-10-23
9
345 Views
Last Modified: 2013-11-17
Hello,
Can someone guide me with using a timer in c?
I'm totally new to c although I'm a bit familiar with "C#".

I just need to store a text file within certain intervals.


I've referred to this article..."http://www.codeproject.com/KB/system/timers_intro.aspx#Win32Timers"...
but I really cannot make sense about how to actually make that stuff real code which really works.
Please help me...
Thanks.
0
Comment
Question by:godwindotnet
  • 5
  • 4
9 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 22784049
You can just use SetTimer :

        http://msdn.microsoft.com/en-us/library/ms644906.aspx

(see the example code on that page)
0
 

Author Comment

by:godwindotnet
ID: 22784105
Where should I paste that code to try it? in the header file or in the c file?
I really dont understand what is the difference between the code they put inside the headers and inside the .c files....(I mean generally in c)
Both look alike to me.

I simply pasted this line ...
SetTimer(hwnd,IDT_TIMER1,10000,(TIMERPROC)NULL);

and it shows me all those errors...
Please help
Thanks...
Error	1	error C2059: syntax error : ','	c:\documents and settings\administrator.dd\desktop\test1\test1\dtmffft\dtmffft.c	149	test1
 
 

Error	2	error C2143: syntax error : missing ')' before 'constant'	c:\documents and settings\administrator.dd\desktop\test1\test1\dtmffft\dtmffft.c	149	test1
 

Error	3	error C2143: syntax error : missing '{' before 'constant'	c:\documents and settings\administrator.dd\desktop\test1\test1\dtmffft\dtmffft.c	149	test1
 

Error	4	error C2059: syntax error : '<Unknown>'	c:\documents and settings\administrator.dd\desktop\test1\test1\dtmffft\dtmffft.c	149	test1

Open in new window

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 22784262
>> I really dont understand what is the difference between the code they put inside the headers and inside the .c files....(I mean generally in c)

The .c files contain the implementation. The .h files contain the exported interface as it will be used by other .c files.


>> and it shows me all those errors...

You need to add the proper includes too :

        #include <windows.h>
0
 

Author Comment

by:godwindotnet
ID: 22784293
But,now it shows this error..
Error      13      error C2065: 'IDT_TIMER1' : undeclared identifier      c:\documents and settings\administrator.dd\desktop\test1\test1\dtmffft\dtmffft.c      960      test1

I'm sorry...but Im totally new to c....I just need this timer part alone working to modify an existing c code to write a value into a file so that my c# application can read it.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 53

Expert Comment

by:Infinity08
ID: 22784465
IDT_TIMER1 is a constant integer value of your choice that identifies the timer (so you can refer to it later).
0
 

Author Comment

by:godwindotnet
ID: 22784558
What should be actually given for the hwnd value?
Can I simply declare a hwnd and give?

and the TIMERPROC is the function that will be called every 10 seconds right?
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 22784640
>> What should be actually given for the hwnd value?

The hwnd is the handle to the window that the timer has to be associated to. Please refer to the reference page I posted earlier.


>> and the TIMERPROC is the function that will be called every 10 seconds right?

Yes.
0
 

Author Comment

by:godwindotnet
ID: 22784671
Alright...Many Thanks :)
0
 

Author Closing Comment

by:godwindotnet
ID: 31509109
Thanks for the time you spent in helping me....
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

705 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

20 Experts available now in Live!

Get 1:1 Help Now