Solved

Using a timer in c

Posted on 2008-10-23
9
350 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-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.

737 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