Solved

Using a timer in c

Posted on 2008-10-23
9
349 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 and use conditional statements in the C programming language.

820 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