Solved

Using a timer in c

Posted on 2008-10-23
9
346 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumHeights  challenge 17 66
Windows Updates failing due to Diskpart not configured correctly 8 104
IIS Log files on Exchange 2013 server 6 82
What is sub-make ? 2 38
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

911 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

16 Experts available now in Live!

Get 1:1 Help Now