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

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [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
    Hanover Germany
    Posts
    20,396

    Re: timeSetEvent and timeKillEvent

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

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    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
    Hanover Germany
    Posts
    20,396

    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
    1,355

    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
    Hanover Germany
    Posts
    20,396

    Re: timeSetEvent and timeKillEvent

    Did you add Winmm.lib?
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    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
    Hanover Germany
    Posts
    20,396

    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
    1,355

    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
    Hanover Germany
    Posts
    20,396

    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
    1,355

    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,449

    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
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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)

  14. #14
    Join Date
    Apr 2009
    Posts
    1,355

    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?

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

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
  •  





Click Here to Expand Forum to Full Width

Featured