Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using a timer in c

Posted on 2008-10-23
9
Medium Priority
?
353 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

885 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