32位SetTimer Windows回调的64位兼容性

时间:2013-01-09 13:25:50

标签: c++ windows 64-bit 32-bit

以前在 32位Windows 上运行的32位Windows c ++应用程序现在需要在64位Windows机器上使用。使用VisualStudio2008。打电话是

SetTimer(m_hWnd, nTimerID, nElapse, *pReceiver)

可以在WinUser.h中找到。

我在编译时将预处理器定义从WIN32更改为WIN64。应用程序在64位PC上编译并运行,但回调没有被触发(应用程序行为使得这很明显)。

是否有解决方法让这个工作?

1 个答案:

答案 0 :(得分:0)

 class DelayedAction
 {

  public:
  DelayedAction( int expirePeriod, boost::function<void()> callback ):
      work( service),
      thread( boost::bind( &DelayedAction::run, this)),
      timer( service),
      m_callback(callback),
      m_expirePeriod(expirePeriod)
  {}

  ~DelayedAction()
  {
      thread.join();
  }

  void startTimer()
  { 
  }

  void on_some_event()
  {
    startAfter(m_expirePeriod);
  }

  void stop()
  {
    timer.cancel();
  }

  void startAfter( const size_t delay)
  {
      // no need to explicitly cancel
      // timer.cancel();
      timer.expires_from_now( boost::posix_time::seconds( delay) );
      timer.async_wait( boost::bind( &DelayedAction::action, this, boost::asio::placeholders::error));
  }



  private:
  void run()
  {
      service.run();
  }

  // ...

  void action(const boost::system::error_code& e) 
  {
      if(e != boost::asio::error::operation_aborted)
          std::cout << "action" << std::endl;
          m_callback();
  }

  int m_expirePeriod;
  boost::function<void()> m_callback;

  boost::asio::io_service         service;
  boost::asio::io_service::work   work;
  boost::thread                   thread;
  boost::asio::deadline_timer     timer;


 };