In C++, I can call functions periodically in the range of milliseconds using the Windows Multimedia timer as following :
timeSetEvent(intPeriod_Milliseconds, 0, vidTimerCallback, ...., TIME_PERIODIC )
where intPeriod_Milliseconds
is an integer variable with the required period in milliseconds.
How can I get the function vidTimerCallback
to be called every 0.5 milliseconds or something in the range of microseconds ?
Now, I have something like this:
#include <windows.h>
double PCFreq = 0.0;
__int64 CounterStart = 0;
void StartCounter()
{
LARGE_INTEGER li;
if(!QueryPerformanceFrequency(&li))
cout << "QueryPerformanceFrequency failed!\n";
PCFreq = double(li.QuadPart)/1000.0;
QueryPerformanceCounter(&li);
CounterStart = li.QuadPart;
}
double GetCounter()
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return double(li.QuadPart-CounterStart)/PCFreq;
}
int main()
{
StartCounter();
Sleep(1000);
cout << GetCounter() <<"\n"; //It prints accurate time like 998
return 0;
}
But I can't further improve it to call a function periodically. I have something similar to this situation using the class here.
Also, I have something that works very well, but it's for C# not C++ (here).