How to use timeSetEvent in C++/CLI
-
I want to use the timeSetEvent in the C++/CLI for a 1msec timing resolution. I seem to have a problem in the CALLBACK function and when i try to replace it with a delegate i have other problems. Can anyone show me the way to use timeSetEvent with a CALLBACK/Delegate function that actually work?
-
I want to use the timeSetEvent in the C++/CLI for a 1msec timing resolution. I seem to have a problem in the CALLBACK function and when i try to replace it with a delegate i have other problems. Can anyone show me the way to use timeSetEvent with a CALLBACK/Delegate function that actually work?
SampleForm::SampleForm() { InitForm(); } void SampleForm::InitForm() { Timer* timer1; timer1 = new Timer(); timer1->Interval = 3000; // 3 seconds resolution timer1->add_Tick(new EventHandler(this,OnTimer)); timer1->Start(); } void SampleForm::OnTimer(System::Object* obj,System::EventArgs* ea) //declare as static method in .h file { } ^-^ @|@ - redCat
-
SampleForm::SampleForm() { InitForm(); } void SampleForm::InitForm() { Timer* timer1; timer1 = new Timer(); timer1->Interval = 3000; // 3 seconds resolution timer1->add_Tick(new EventHandler(this,OnTimer)); timer1->Start(); } void SampleForm::OnTimer(System::Object* obj,System::EventArgs* ea) //declare as static method in .h file { } ^-^ @|@ - redCat
this is now the timeSetEvent, but the Timer class. The Timer class accuracy is very poor, unlike the timeSetEvent. Can anybody show me how to use it in c++/cli .net 2005?
-
this is now the timeSetEvent, but the Timer class. The Timer class accuracy is very poor, unlike the timeSetEvent. Can anybody show me how to use it in c++/cli .net 2005?
First of all, you should note that accuracy is not the same as precision[^]. 10ms is pretty much the most accurate you can get with Win32, without screwing with the operating system metrics or reinstalling the HAL. But anyway, you use timeSetEvent in C++/CLI the same way you use it in Win32.
#include #pragma comment(lib, "winmm")
public ref class TimerWrapper
{
EventHandle ^eventHandle;
public:
TimerWrapper()
: eventHandle(false, EventResetMode::AutoReset)
{
}int TimerFunc()
{
for( ; ; )
{
eventHandle->WaitOne();
...
}
}void UseTimeEvent()
{
timeSetEvent(100, 55, reinterpret_cast(
eventHandle->SafeWaitHandle->DangerousWaitHandle().ToPointer()),
0, TIME_ONESHOT | TIME_CALLBACK_EVENT_SET);
...
}
};-- modified at 17:31 Saturday 13th May, 2006