Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Multimedia Timer Problem in MFC VS2010

Multimedia Timer Problem in MFC VS2010

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++csharpcssvisual-studio
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lephanhung
    wrote on last edited by
    #1

    I want to use a mm_timer for my application by 60Hz or less :-D . This is my testing code. - In "testmmtimerDlg.h" header file:

    #include "mmsystem.h"
    #pragma once
    #pragma comment(lib, "winmm.lib")

    public:
    double m_dcount;
    static void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

    void MMTimerHandler(UINT nIDEvent);
    void StopTimer();
    	
    MMRESULT m\_Timer;	
    DWORD resolution;</pre>
    
    • In "testmmtimerDlg.cpp" file:

    void CtestmmtimerDlg::OnBnClickedTest()
    {
    // TODO: Add your control notification handler code here
    m_dcount = 0;
    // Set resolution to the minimum supported by the system

    TIMECAPS tc;
    timeGetDevCaps(&tc, sizeof(TIMECAPS));
    resolution = min(max(tc.wPeriodMin, 0), tc.wPeriodMax);
    timeBeginPeriod(resolution);
    
    // create the timer
    m\_Timer = timeSetEvent(10,resolution,TimeProc,(DWORD)this,TIME\_PERIODIC);
    

    }

    void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
    {
    // This is used only to call MMTimerHandler

    // Typically, this function is static member of CTimersDlg
    
    CtestmmtimerDlg\* obj = (CtestmmtimerDlg\*) dwUser;
    obj->MMTimerHandler(wTimerID);
    

    }

    void CtestmmtimerDlg::StopTimer()
    {
    // destroy the timer
    timeKillEvent(m_Timer);

    // reset the timer
    timeEndPeriod (resolution);
    

    }

    ==>> But when I try to debug, I have 2 problem:

    • First, "

    testmmtimerDlg.obj : error LNK2019: unresolved external symbol "public: static void __stdcall CtestmmtimerDlg::TimeProc(unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)" (?TimeProc@CtestmmtimerDlg@@SGXIIKKK@Z) referenced in function "public: void __thiscall CtestmmtimerDlg::OnBnClickedTest(void)" (?OnBnClickedTest@CtestmmtimerDlg@@QAEXXZ)
    1>C:\Users\HungReo\Documents\Visual Studio 2010\Projects\testmmtimer\Debug\testmmtimer.exe : fatal error LNK1120: 1 unresolved externals

    "

    • Second, in header file, I try to change:

    void (CALLBACK *TimeProc)(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

    ==>>>> OxC0000005: Access Violoation

    • May someone help me to solve these problem???
    L 1 Reply Last reply
    0
    • L lephanhung

      I want to use a mm_timer for my application by 60Hz or less :-D . This is my testing code. - In "testmmtimerDlg.h" header file:

      #include "mmsystem.h"
      #pragma once
      #pragma comment(lib, "winmm.lib")

      public:
      double m_dcount;
      static void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

      void MMTimerHandler(UINT nIDEvent);
      void StopTimer();
      	
      MMRESULT m\_Timer;	
      DWORD resolution;</pre>
      
      • In "testmmtimerDlg.cpp" file:

      void CtestmmtimerDlg::OnBnClickedTest()
      {
      // TODO: Add your control notification handler code here
      m_dcount = 0;
      // Set resolution to the minimum supported by the system

      TIMECAPS tc;
      timeGetDevCaps(&tc, sizeof(TIMECAPS));
      resolution = min(max(tc.wPeriodMin, 0), tc.wPeriodMax);
      timeBeginPeriod(resolution);
      
      // create the timer
      m\_Timer = timeSetEvent(10,resolution,TimeProc,(DWORD)this,TIME\_PERIODIC);
      

      }

      void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
      {
      // This is used only to call MMTimerHandler

      // Typically, this function is static member of CTimersDlg
      
      CtestmmtimerDlg\* obj = (CtestmmtimerDlg\*) dwUser;
      obj->MMTimerHandler(wTimerID);
      

      }

      void CtestmmtimerDlg::StopTimer()
      {
      // destroy the timer
      timeKillEvent(m_Timer);

      // reset the timer
      timeEndPeriod (resolution);
      

      }

      ==>> But when I try to debug, I have 2 problem:

      • First, "

      testmmtimerDlg.obj : error LNK2019: unresolved external symbol "public: static void __stdcall CtestmmtimerDlg::TimeProc(unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)" (?TimeProc@CtestmmtimerDlg@@SGXIIKKK@Z) referenced in function "public: void __thiscall CtestmmtimerDlg::OnBnClickedTest(void)" (?OnBnClickedTest@CtestmmtimerDlg@@QAEXXZ)
      1>C:\Users\HungReo\Documents\Visual Studio 2010\Projects\testmmtimer\Debug\testmmtimer.exe : fatal error LNK1120: 1 unresolved externals

      "

      • Second, in header file, I try to change:

      void (CALLBACK *TimeProc)(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

      ==>>>> OxC0000005: Access Violoation

      • May someone help me to solve these problem???
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      void (CALLBACK *TimeProc)(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

      You are declaring TimeProc as a pointer to a function which is totally incorrect. It should be like:

      // in the class definition in the header file:
      void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

      // and the declaration in the .cpp file:
      void CALLBACK CtestmmtimerDlg::TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
      {
      // implementation code here
      }

      L 2 Replies Last reply
      0
      • L Lost User

        void (CALLBACK *TimeProc)(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

        You are declaring TimeProc as a pointer to a function which is totally incorrect. It should be like:

        // in the class definition in the header file:
        void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

        // and the declaration in the .cpp file:
        void CALLBACK CtestmmtimerDlg::TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
        {
        // implementation code here
        }

        L Offline
        L Offline
        lephanhung
        wrote on last edited by
        #3

        Thank you very much for your help! But when I try to follow your code, the error will be:

        error C3867: 'CtestmmtimerDlg::TimeProc': function call missing argument list; use '&CtestmmtimerDlg::TimeProc' to create a pointer to member

        1 Reply Last reply
        0
        • L Lost User

          void (CALLBACK *TimeProc)(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

          You are declaring TimeProc as a pointer to a function which is totally incorrect. It should be like:

          // in the class definition in the header file:
          void CALLBACK TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

          // and the declaration in the .cpp file:
          void CALLBACK CtestmmtimerDlg::TimeProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
          {
          // implementation code here
          }

          L Offline
          L Offline
          lephanhung
          wrote on last edited by
          #4

          I finished to run it ^^. Just move the CALLBACK function before click button and don't need to declare CALLBACK in header file. Thank you so much for your help ^^

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups