CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    timers with 1ms of precision

    i don't belive that there isn't timers with 1ms of precision, but i can't get any help. and i try search and nothing.
    please can anyone give me something for start dooing a timer with 1ms of precision?

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

    Re: timers with 1ms of precision

    Not 100 % sure about 1 ms, but try multimedia timers
    Victor Nijegorodov

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

    Re: timers with 1ms of precision

    Quote Originally Posted by VictorN View Post
    Not 100 % sure about 1 ms, but try multimedia timers
    i found these function

    CreateTimerQueueTimer() maybe i find 1 sample. but, please see my class:
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <Mmsystem.h>
    
    class Timer
    {
        private: 
            int MilliSecondsTimer;
        private:
            bool blnDestroyed;
        private:
            HANDLE Handle_Of_Thread_1;
         typedef void (*MyTimerProc)();
        MyTimerProc TimerProcedure;
         static DWORD WINAPI StaticThreadProc(LPVOID param) {
            static_cast<Timer*>(param)->MultithreadProcedure();
            return 0;
            }
        public: 
            int SetMilliSeconds(int MilliSeconds)
            {
                MilliSecondsTimer = MilliSeconds;
                return 0;
            }
        public: 
            int GetMilliSeconds()
            {
                return (MilliSecondsTimer);
            }
        private: void   MultithreadProcedure() 
            {
                /*LARGE_INTEGER liFrequency;
                LARGE_INTEGER liStartTime;
                LARGE_INTEGER liCurrentTime;
                double a;
    
                QueryPerformanceFrequency ( &liFrequency );
            
                QueryPerformanceCounter ( &liStartTime );
                for (;;)
                {
                    QueryPerformanceCounter ( &liCurrentTime );
                    a=(int) ((double)( (liCurrentTime.QuadPart - liStartTime.QuadPart)* (double)1000.0/(double)liFrequency.QuadPart ));
                    if (a>=MilliSecondsTimer) 
                    {
                        TimerProcedure();
                        QueryPerformanceCounter ( &liStartTime );
                    
                    }
    
    
                    if (blnDestroyed==true)  break;
                }*/
                int a=0;
                for (;;)
                {
                    if (blnDestroyed==true) break;
                    timeBeginPeriod(1) ;
                    Sleep(1) ; 
                    timeEndPeriod(1);
                    a=a+1;
                    if (a ==MilliSecondsTimer)
                    {
                        TimerProcedure();
                        a=0;                    
                    }
                }
                CloseHandle(Handle_Of_Thread_1);
                TerminateThread( Handle_Of_Thread_1,1);
            }
        public:
            int Start(MyTimerProc TimerProc) 
            {
                TimerProcedure = TimerProc;
                Handle_Of_Thread_1=0;
                CloseHandle(Handle_Of_Thread_1);
                TerminateThread( Handle_Of_Thread_1,1);
                blnDestroyed=false;
                HANDLE hMyThread;
                hMyThread = CreateThread(NULL, 0, StaticThreadProc, this, 0, NULL);
                return 0;
            }
        public: int Destroy()
            {
                blnDestroyed=true;            
                return 0;
            }
    };
    
    Timer test;
    
    int a;
    
    void  TimerProcedure()
    {
        system("cls");
        a=a+1;
        printf("%d\n",a);
    }
    
    
    
    void main()
    {
        test.SetMilliSeconds(10);
        
        test.Start(TimerProcedure);
        
        
        getch();
        test.Destroy();
        
    }
    why i don't get 100ms( or 10ms, at least)?

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

    Re: timers with 1ms of precision

    Victor Nijegorodov

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

    Re: timers with 1ms of precision

    anotherthing: i'm using VC++6, why CreateTimerQueueTimer() isn't in list?
    how can i use it without a problems?

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

    Re: timers with 1ms of precision

    From MSDN October 2000:
    Requirements
    Windows NT/2000: Requires Windows 2000.
    Windows 95/98: Unsupported.
    Header: Declared in Winbase.h; include Windows.h.
    Library: Use Kernel32.lib.
    and perhaps you will need the latest SDK (from February 2003) compatible with VC++6.0
    Victor Nijegorodov

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

    Re: timers with 1ms of precision

    Quote Originally Posted by VictorN View Post
    From MSDN October 2000:and perhaps you will need the latest SDK (from February 2003) compatible with VC++6.0
    sorry where i get that?

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

    Re: timers with 1ms of precision

    Use Google...
    Victor Nijegorodov

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

    Re: timers with 1ms of precision

    Quote Originally Posted by VictorN View Post
    Use Google...
    i don't test it, but i found here: http://wiki.tcl.tk/11970
    thanks

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

    Re: timers with 1ms of precision

    Quote Originally Posted by Cambalinho View Post
    i don't test it, but i found here: http://wiki.tcl.tk/11970
    thanks
    it looks promising!
    Victor Nijegorodov

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

    Re: timers with 1ms of precision

    i can't execute the exe on my windows7 and i can't extract manualy

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

    Re: timers with 1ms of precision

    Define "can't execute the exe"
    BTW, could you install VC++6.0 on your windows7?
    Victor Nijegorodov

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

    Re: timers with 1ms of precision

    Quote Originally Posted by VictorN View Post
    Define "can't execute the exe"
    BTW, could you install VC++6.0 on your windows7?
    "Define "can't execute the exe""
    just open the window and then close it.

    "BTW, could you install VC++6.0 on your windows7?"
    yes i could and was easy. but i install the Visual Studio 98(and better install SP6 for correct the errors).

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

    Re: timers with 1ms of precision

    Quote Originally Posted by Cambalinho View Post
    "Define "can't execute the exe""
    just open the window and then close it.
    But why do you execute it directly?
    You have to start the PSDK-FULL.bat file!
    Victor Nijegorodov

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

    Re: timers with 1ms of precision

    Quote Originally Posted by VictorN View Post
    But why do you execute it directly?
    You have to start the PSDK-FULL.bat file!
    the resolte is the same

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