-
April 26th, 2013, 09:23 AM
#1
[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?
-
April 26th, 2013, 10:02 AM
#2
Re: timeSetEvent and timeKillEvent
Callback function must be either global or static class member.
Victor Nijegorodov
-
April 26th, 2013, 10:21 AM
#3
Re: timeSetEvent and timeKillEvent
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."
-
April 26th, 2013, 10:35 AM
#4
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;
}
Victor Nijegorodov
-
April 26th, 2013, 10:50 AM
#5
Re: timeSetEvent and timeKillEvent
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)"
-
April 26th, 2013, 10:52 AM
#6
Re: timeSetEvent and timeKillEvent
Victor Nijegorodov
-
April 26th, 2013, 11:20 AM
#7
Re: timeSetEvent and timeKillEvent
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?
-
April 26th, 2013, 11:26 AM
#8
Re: timeSetEvent and timeKillEvent
You can add
#pragma comment(lib, "Winmm.lib")
in your .cpp file
Victor Nijegorodov
-
April 26th, 2013, 11:52 AM
#9
Re: timeSetEvent and timeKillEvent
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
-
April 26th, 2013, 12:02 PM
#10
Re: timeSetEvent and timeKillEvent
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!
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.
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.
Victor Nijegorodov
-
April 26th, 2013, 12:20 PM
#11
Re: timeSetEvent and timeKillEvent
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
-
April 26th, 2013, 12:47 PM
#12
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
-
April 26th, 2013, 12:55 PM
#13
Re: timeSetEvent and timeKillEvent
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)?
-
April 26th, 2013, 01:25 PM
#14
Re: [RESOLVED] timeSetEvent and timeKillEvent
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).
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 26th, 2013, 01:54 PM
#15
Re: [RESOLVED] timeSetEvent and timeKillEvent
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?
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
|