[RESOLVED] timeSetEvent and timeKillEvent
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: [RESOLVED] timeSetEvent and timeKillEvent

  1. #1
    Join Date
    Apr 2009
    Posts
    626

    [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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: timeSetEvent and timeKillEvent

    Callback function must be either global or static class member.
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    626

    Re: timeSetEvent and timeKillEvent

    Quote Originally Posted by VictorN View Post
    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."

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    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

  5. #5
    Join Date
    Apr 2009
    Posts
    626

    Re: timeSetEvent and timeKillEvent

    Quote Originally Posted by VictorN View Post
    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)"

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: timeSetEvent and timeKillEvent

    Did you add Winmm.lib?
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2009
    Posts
    626

    Re: timeSetEvent and timeKillEvent

    Quote Originally Posted by VictorN View Post
    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?

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: timeSetEvent and timeKillEvent

    You can add
    #pragma comment(lib, "Winmm.lib")
    in your .cpp file
    Victor Nijegorodov

  9. #9
    Join Date
    Apr 2009
    Posts
    626

    Re: timeSetEvent and timeKillEvent

    Quote Originally Posted by VictorN View Post
    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

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: timeSetEvent and timeKillEvent

    Quote Originally Posted by Cambalinho View Post
    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 View Post
    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 View Post
    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

  11. #11
    Join Date
    Apr 2009
    Posts
    626

    Re: timeSetEvent and timeKillEvent

    Quote Originally Posted by VictorN View Post
    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

  12. #12
    Join Date
    Apr 1999
    Posts
    27,426

    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

  13. #13
    Join Date
    Apr 2009
    Posts
    626

    Re: timeSetEvent and timeKillEvent

    Quote Originally Posted by Paul McKenzie View Post
    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)?

  14. #14
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,328

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  15. #15
    Join Date
    Apr 2009
    Posts
    626

    Re: [RESOLVED] timeSetEvent and timeKillEvent

    Quote Originally Posted by 2kaud View Post
    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?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center