|
-
Aug 13th, 2002, 10:06 AM
#1
Thread Starter
Ya ya Baby!!!Me is Back
Timers in console ?
I have read something in the HELP of MSDN and it said that it will add something in the main of the program like that :
Code:
case WM_TIMER:
switch (wParam)
{
case IDT_TIMER1:
...............
But is that only when it's not a console ? Cause I do not know where to add that code in a console ?
-
Aug 14th, 2002, 03:13 PM
#2
Thread Starter
Ya ya Baby!!!Me is Back
Can we use TIMER in console application?
The answer is boolean, yes or no
-
Aug 14th, 2002, 03:33 PM
#3
Monday Morning Lunatic
Just make life easy and use timeSetEvent, which is far more accurate, and it doesn't mess up the message queue (just calls your function when it times out).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 14th, 2002, 05:54 PM
#4
Thread Starter
Ya ya Baby!!!Me is Back
timeSetEvent...hummm I will read about it in MSDN help, thx
-
Aug 14th, 2002, 06:17 PM
#5
Thread Starter
Ya ya Baby!!!Me is Back
Code:
#include <iostream>
#include <mmsystem.h>
using namespace std;
void Print(void);
void main()
{
timeSetEvent(
1000,
0,
Print(),
0,
0);
}//End main
void Print(void)
{
cout << "ForEVER" << endl;
}//End print
[error]
mainSource.cpp
c:\program files\microsoft visual studio\vc98\include\mmsystem.h(113) : error C2146: syntax error : missing ';' before identifier 'MMVERSION'
c:\program files\microsoft visual studio\vc98\include\mmsystem.h(113) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
[/error]
What do I do wrong?
-
Aug 15th, 2002, 06:27 PM
#6
Monday Morning Lunatic
Did you #include <windows.h> before mmsystem.h?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 15th, 2002, 07:09 PM
#7
Frenzied Member
but i thought all windows functions were included in windows.h....
guess not
retired member. Thanks for everything 
-
Aug 15th, 2002, 07:16 PM
#8
Thread Starter
Ya ya Baby!!!Me is Back
OK now I have an other error :
Code:
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
using namespace std;
void Print(void);
void main()
{
timeSetEvent(
1000,
0,
Print(),
0,
0);
}//End main
void Print(void)
{
cout << "ForEVER" << endl;
}//End print
error C2664: 'timeSetEvent' : cannot convert parameter 3 from 'void' to 'void (__stdcall *)(unsigned int,unsigned int,unsigned long,unsigned l
ong,unsigned long)'
Expressions of type void cannot be converted to other types
Error executing cl.exe.
-
Aug 16th, 2002, 11:18 PM
#9
PowerPoster
Try declaring Print() something like this:
PHP Code:
void Print(unsigned int something,unsigned int bah,unsigned long what,unsigned long hmm,unsigned long geeky);
Look at the reference for setTimeEvent to see what the parameters are.
-
Aug 18th, 2002, 04:38 PM
#10
Thread Starter
Ya ya Baby!!!Me is Back
I do not understand why I have to do that?
-
Aug 18th, 2002, 05:09 PM
#11
PowerPoster
It said "cannot convert parameter 3 from 'void' to 'void (__stdcall *)(unsigned int,unsigned int,unsigned long,unsigned l
ong,unsigned long)" so it's probably not able to use the parameter void. Try it and see if it works.
-
Aug 19th, 2002, 06:48 AM
#12
Monday Morning Lunatic
The function needs to have the __stdcall attribute, as the error said
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 19th, 2002, 08:08 AM
#13
Member
I think the problem here is in the "()" after Print. C expects a pointer to a function, and the way you're doing this now is calling the function and passing the return value (a void) to timeSetEvent.
The following code might work:
Code:
timeSetEvent(
1000,
0,
Print,
0,
0);
Edit: Oh, and mmsystem.h is included in windows.h, so you only need to #include <windows.h>
Last edited by Stef; Aug 19th, 2002 at 08:11 AM.
-
Aug 19th, 2002, 07:53 PM
#14
Thread Starter
Ya ya Baby!!!Me is Back
PHP Code:
#include <iostream>
#include <windows.h>
//#include <mmsystem.h>
using namespace std;
void Print(void);
void main()
{
timeSetEvent(
1000,
0,
Print,
0,
0);
}//End main
void Print(void)
{
cout << "ForEVER" << endl;
}//End print
Code:
error C2664: 'timeSetEvent' : cannot convert parameter 3 from 'void (void)' to 'void (__stdcall *)(unsigned int,unsigned int,unsigned long,uns
igned long,unsigned long)'
None of the functions with this name in scope match the target type
Error executing cl.exe.
-
Aug 20th, 2002, 07:16 AM
#15
Member
Ah, I got it to work now 
For some reason timeSetEvent expects a callback function with a lot of parameters. I don't know what they are, but you could experiment with them if you want. Otherwise, just ignore them as I have done in the following code.
(The while() is just to make sure the program doesn't end before the timer is activated)
Code:
#include <iostream.h>
#include <windows.h>
//using namespace std;
int g_Stop = 0;
void CALLBACK Print(unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)
{
cout << "ForEVER" << endl;
g_Stop = 1;
}//End print
int main()
{
timeSetEvent(
1000,
0,
Print,
0,
0);
while( g_Stop == 0 )
{
cout << ".";
}
return 0;
}//End main
-
Aug 20th, 2002, 05:23 PM
#16
Thread Starter
Ya ya Baby!!!Me is Back
Back to my old name!
THX! I will check that code later, and check about CALLBACK, I never used that word before
-
Aug 20th, 2002, 05:26 PM
#17
Thread Starter
Ya ya Baby!!!Me is Back
Here is what I got :
Code:
Compiling...
mainSource.cpp
Linking...
mainSource.obj : error LNK2001: unresolved external symbol __imp__timeSetEvent@20
Debug/DosTimer.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
DosTimer.exe - 2 error(s), 0 warning(s)
Error are in the linkage
-
Aug 20th, 2002, 05:55 PM
#18
PowerPoster
You probably forgot to include windows.h that's why you're getting the linking error.
I think CALLBACK is defined as _stdcall and setTimeEvent requires the function to be declared as such.
-
Aug 20th, 2002, 06:47 PM
#19
Thread Starter
Ya ya Baby!!!Me is Back
I have windows.h, I copy and paste Stef code's
-
Aug 21st, 2002, 07:47 AM
#20
Member
Ah, sorry, forgot to tell you about that.
- Go to Project > Settings
- Choose "All configurations" from the drop down menu (on the left)
- Go to the Link tab
- Add winmm.lib to the line labeled "Object/library modules"
-
Aug 22nd, 2002, 05:57 AM
#21
If you have VC7 right-click your project in the solution explorer, choose properties, then select the project again if you have to, then go to linker-> input and add the library there
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 2nd, 2002, 09:51 AM
#22
Thread Starter
Ya ya Baby!!!Me is Back
I have lost the link to that thread and I just tested it and it work!
Thx all
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|