[RESOLVED] timeSetEvent and timeKillEvent
i'm trying build a timer inside of class:
Code:
class subimages
{
public: int ActualSubimage;
public: int MilliSecondsTimer;
public: int TotalSubimages;
public: ImageInfo *SubImages;
public: bool TransparentImages;
private: bool blnAnimation;
private: MMRESULT timerID;
private: void CALLBACK TimerFunction(UINT wTimerID, UINT msg,
DWORD dwUser, DWORD dw1, DWORD dw2)
{
if (ActualSubimage == TotalSubimages)
ActualSubimage = 0;
else
ActualSubimage = ActualSubimage + 1;
;
}
public: void AnimationStart()
{
blnAnimation = true;
timerID =timeSetEvent(MilliSecondsTimer , 0, TimerFunction, (DWORD)this, TIME_PERIODIC);;
}
public: void AnimationStop()
{
blnAnimation = false;
timeKillEvent(timerID);
}
.......................
but i get these error:
"--------------------Configuration: Sprite2 - Win32 Debug--------------------
Compiling...
Test Sprite2.cpp
c:\users\joaquim\documents\visual c 98\sprite2\sprite2.h(55) : error C2664: 'timeSetEvent' : cannot convert parameter 3 from 'void (unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)' to 'void (__stdcall *)(unsigned int,unsigned in
t,unsigned long,unsigned long,unsigned long)'
None of the functions with this name in scope match the target type
Error executing cl.exe.
Sprite2.exe - 1 error(s), 0 warning(s)"
(i'm using VC++6)
i don't understand why the error(the documents that i read are limited):(
can anyone advice me?
Re: timeSetEvent and timeKillEvent
Callback function must be either global or static class member.
Re: timeSetEvent and timeKillEvent
Quote:
Originally Posted by
VictorN
Callback function must be either global or static class member.
sorry but i get errors:(
Code:
public: static void CALLBACK TimerFunction(UINT wTimerID, UINT msg,
DWORD dwUser, DWORD dw1, DWORD dw2)
{
if (ActualSubimage == TotalSubimages)
ActualSubimage = 0;
else
ActualSubimage = ActualSubimage + 1;
}
error messages:
"--------------------Configuration: Sprite2 - Win32 Debug--------------------
Compiling...
Test Sprite2.cpp
c:\users\joaquim\documents\visual c 98\sprite2\sprite2.h(44) : error C2597: illegal reference to data member 'subimages::ActualSubimage' in a static member function
c:\users\joaquim\documents\visual c 98\sprite2\sprite2.h(44) : error C2597: illegal reference to data member 'subimages::TotalSubimages' in a static member function
c:\users\joaquim\documents\visual c 98\sprite2\sprite2.h(44) : error C2568: '==' : unable to resolve function overload
c:\users\joaquim\documents\visual c 98\sprite2\sprite2.h(45) : error C2597: illegal reference to data member 'subimages::ActualSubimage' in a static member function
c:\users\joaquim\documents\visual c 98\sprite2\sprite2.h(47) : error C2597: illegal reference to data member 'subimages::ActualSubimage' in a static member function
c:\users\joaquim\documents\visual c 98\sprite2\sprite2.h(47) : error C2597: illegal reference to data member 'subimages::ActualSubimage' in a static member function
Error executing cl.exe."
:(
Re: timeSetEvent and timeKillEvent
Well, static member fuction has no idea about class members!
To pass a pointer to a class object you could use dwUser parameter. Then (pseudo/code):
Code:
// note that you already passed this pointer as user data!
public: void AnimationStart()
{
blnAnimation = true;
timerID =timeSetEvent(MilliSecondsTimer , 0, TimerFunction, (DWORD)this, TIME_PERIODIC);;
}
....
DWORD dwUser, DWORD dw1, DWORD dw2)
{
subimages* ptr = (subimages*)dwUser;
if (ptr->ActualSubimage == ptr->TotalSubimages)
ptr->ActualSubimage = 0;
else
ptr->ActualSubimage = ptr->ActualSubimage + 1;
}
Re: timeSetEvent and timeKillEvent
Quote:
Originally Posted by
VictorN
Well, static member fuction has no idea about class members!
To pass a pointer to a class object you could use
dwUser parameter. Then (pseudo/code):
Code:
// note that you already passed this pointer as user data!
public: void AnimationStart()
{
blnAnimation = true;
timerID =timeSetEvent(MilliSecondsTimer , 0, TimerFunction, (DWORD)this, TIME_PERIODIC);;
}
....
DWORD dwUser, DWORD dw1, DWORD dw2)
{
subimages* ptr = (subimages*)dwUser;
if (ptr->ActualSubimage == ptr->TotalSubimages)
ptr->ActualSubimage = 0;
else
ptr->ActualSubimage = ptr->ActualSubimage + 1;
}
sorry.. i continue with errors:(
"Deleting intermediate files and output files for project 'Sprite2 - Win32 Debug'.
--------------------Configuration: Sprite2 - Win32 Debug--------------------
Compiling...
Test Sprite2.cpp
Linking...
Test Sprite2.obj : error LNK2001: unresolved external symbol __imp__timeSetEvent@20
Test Sprite2.obj : error LNK2001: unresolved external symbol __imp__timeKillEvent@4
Debug/Sprite2.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Sprite2.exe - 3 error(s), 0 warning(s)"
Re: timeSetEvent and timeKillEvent
Re: timeSetEvent and timeKillEvent
Quote:
Originally Posted by
VictorN
Did you add Winmm.lib?
thanks... now works.
i have 1 question: is possible join that file by code or i must, allways, inclued when i use the timer?
Re: timeSetEvent and timeKillEvent
You can add
#pragma comment(lib, "Winmm.lib")
in your .cpp file
Re: timeSetEvent and timeKillEvent
Quote:
Originally Posted by
VictorN
You can add
#pragma comment(lib, "Winmm.lib")
in your .cpp file
and in .h file(because i have there my class)?
another question: when they said that is a .dll and .lib what file we inclued?
can you give me a nice link for i see better how build a timer(inclued the callback function(that was my big problem))?
thanks for all my friend.. realy.. .thanks
Re: timeSetEvent and timeKillEvent
Quote:
Originally Posted by
Cambalinho
and in .h file(because i have there my class)?
another question: when they said that is a .dll and .lib what file we inclued?
Perhaps. Sorry I never tried!
Quote:
Originally Posted by
Cambalinho
another question: when they said that is a .dll and .lib what file we inclued?
included must be a header file.
But in many cases you must also use additional library files (that were not added to some "standard" build). Those files should be added in the Linker Additional Dependencies (either direct in the corresponding Project Property Page) or via #pragma comment.
Quote:
Originally Posted by
Cambalinho
can you give me a nice link for i see better how build a timer(inclued the callback function(that was my big problem))?
thanks for all my friend.. realy.. .thanks
No, I cannot. I never used Multimedia Timer.
Re: timeSetEvent and timeKillEvent
Quote:
Originally Posted by
VictorN
Perhaps. Sorry I never tried!
included must be a header file.
But in many cases you must also use additional library files (that were not added to some "standard" build). Those files should be added in the Linker Additional Dependencies (either direct in the corresponding Project Property Page) or via #pragma comment.
No, I cannot. I never used Multimedia Timer.
thanks for all
Re: timeSetEvent and timeKillEvent
On a side note, your style of specifying your member variables is not C++ style. This is what I'm talking about:
Code:
public: int ActualSubimage;
public: int MilliSecondsTimer;
public: int TotalSubimages;
public: ImageInfo *SubImages;
public: bool TransparentImages;
private: bool blnAnimation;
private: MMRESULT timerID;
C++ is not Java. You don't need to specify the access specifier for each member.
Code:
public:
int ActualSubimage;
int MilliSecondsTimer;
int TotalSubimages;
ImageInfo *SubImages;
bool TransparentImages;
private:
bool blnAnimation;
MMRESULT timerID;
That is what any C++ programmer would expect to see.
Regards,
Paul McKenzie
Re: timeSetEvent and timeKillEvent
Quote:
Originally Posted by
Paul McKenzie
On a side note, your style of specifying your member variables is not C++ style. This is what I'm talking about
:
Code:
public: int ActualSubimage;
public: int MilliSecondsTimer;
public: int TotalSubimages;
public: ImageInfo *SubImages;
public: bool TransparentImages;
private: bool blnAnimation;
private: MMRESULT timerID;
C++ is not Java. You don't need to specify the access specifier for each member.
Code:
public:
int ActualSubimage;
int MilliSecondsTimer;
int TotalSubimages;
ImageInfo *SubImages;
bool TransparentImages;
private:
bool blnAnimation;
MMRESULT timerID;
That is what any C++ programmer would expect to see.
Regards,
Paul McKenzie
the private and public are new for me. i never knew about that. thanks.. honestly i love indent the code;)
but all that variables are public(until find private keyword)?
Re: [RESOLVED] timeSetEvent and timeKillEvent
Quote:
but all that variables are public(until find private keyword)?
In a class by default all entities are private unless otherwise stated as public or protected. Once public: or private: or protected: is used then all subsequent entities are of this specifier until a new specifier is stated. (Note that in a struct all entities are public unless otherwise stated etc).
Re: [RESOLVED] timeSetEvent and timeKillEvent
Quote:
Originally Posted by
2kaud
In a class by default all entities are private unless otherwise stated as public or protected. Once public: or private: or protected: is used then all subsequent entities are of this specifier until a new specifier is stated. (Note that in a struct all entities are public unless otherwise stated etc).
i understand private and public, but can you explain to me static and protected?