Click here to Skip to main content
15,910,009 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: DLL: GetProcAddress() always returns NULL?? Pin
registering11-Dec-04 4:37
registering11-Dec-04 4:37 
QuestionWhat is the include needed? Pin
Anonymous10-Dec-04 9:43
Anonymous10-Dec-04 9:43 
AnswerRe: What is the include needed? Pin
John M. Drescher10-Dec-04 9:53
John M. Drescher10-Dec-04 9:53 
AnswerRe: What is the include needed? Pin
Andy Hunter10-Dec-04 10:07
Andy Hunter10-Dec-04 10:07 
GeneralRe: What is the include needed? Pin
Anonymous10-Dec-04 10:09
Anonymous10-Dec-04 10:09 
GeneralEvents - How Fast Pin
Grahamfff10-Dec-04 8:47
Grahamfff10-Dec-04 8:47 
GeneralRe: Events - How Fast Pin
John M. Drescher10-Dec-04 10:39
John M. Drescher10-Dec-04 10:39 
GeneralRe: Events - How Fast Pin
Antti Keskinen10-Dec-04 10:39
Antti Keskinen10-Dec-04 10:39 
Hello !

Windows is not the best platform for time-critical applications. If you must use it, though, you could try increasing the priority of your application to maximum level. This ensures that the 40 ms (I assume milliseconds, here)timer is fired as close to 40 ms intervals as possible.

Increasing the priority of your application will cause other applications to lose theirs: increasing the accuracy of your application might/will cause inaccuracy/stiff response/high latency in other applications concurrently executing in the system. Pushing one application to real-time priority will most likely cause the operating system to appear 'locked up' while this single application is executing. The timer will reach as close to 40 ms intervals as possible, though. That's the price you'll have to pay.

When designing the real-time thread, you must make it as low-resource hog as possible.

For an example, create a thread, increase it's priority and call SetTimer Win32 API routine with a pointer to the function that should run at 40 ms intervals. Then put this thread into a forever loop that can be interrupted, if necessary. When interrupted, the timer should be killed and the thread terminated. Note that this will not cause the system to lock up, because the priority of the process itself has not been raised. You could use SetPriorityClass to pump up the process priority as well. Before doing this, familiarize yourself with Scheduling Priorities[^] in the MSDN or in Visual Studio documentation. Misusing thread or process priorities is a sure way to get your computer locked up easily.

To set max priority for your MFC application's main thread, use AfxGetApp() to get the CWinApp object pointer, and call CWinThread::SetThreadPriority() with a parameter THREAD_PRIORITY_TIME_CRITICAL through this pointer. CWinApp derives from CWinThread. MFC does not have a direct routine to pump up process priority. You'd need to use a mixed-mode call (CWinThread::operator HANDLE and SetPriorityClass) to accomplish this.

A precisely 40 ms timer with not a single micro-second delay or advance is impossible in a modern operating system. For such a purpose, you'd need to design and implement a micro-controller or similar solution.

Named events are used to schedule interprocess actions, or interthread actions. For example, you could create an event object in a remote thread to mark when this thread has ran a single loop. When the event object is signaled, a loop is complete and the next loop is starting, if it's a continous system. Event objects can be global or local, determining how they are created. Global of interprocess, local for interthread should be your general rule.

Even if you used named events, you would need some method to set the event to a signaled state whenever 40 ms has passed. This will again lead you back to the timing issue and the timers. Named events is the easiest way to signal other threads or processes that your 40 ms interval has passed, though.

Hope this helps.

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: Events - How Fast Pin
Mike Dimmick10-Dec-04 12:33
Mike Dimmick10-Dec-04 12:33 
GeneralOnRButtonUp Pin
greba10-Dec-04 8:33
greba10-Dec-04 8:33 
GeneralRe: OnRButtonUp Pin
greba10-Dec-04 9:13
greba10-Dec-04 9:13 
GeneralRe: OnRButtonUp Pin
G. Steudtel10-Dec-04 9:16
G. Steudtel10-Dec-04 9:16 
Generalregular experssion in C++ Pin
pnpfriend10-Dec-04 7:47
pnpfriend10-Dec-04 7:47 
GeneralRe: regular experssion in C++ Pin
John M. Drescher10-Dec-04 8:03
John M. Drescher10-Dec-04 8:03 
GeneralRe: regular experssion in C++ Pin
Jack Puppy10-Dec-04 11:17
Jack Puppy10-Dec-04 11:17 
GeneralRe: regular experssion in C++ Pin
John R. Shaw10-Dec-04 18:44
John R. Shaw10-Dec-04 18:44 
GeneralCDC::BitBlt(...) - strange speed variations Pin
moredip10-Dec-04 7:01
moredip10-Dec-04 7:01 
GeneralRe: CDC::BitBlt(...) - strange speed variations Pin
G. Steudtel10-Dec-04 7:22
G. Steudtel10-Dec-04 7:22 
GeneralRe: CDC::BitBlt(...) - strange speed variations Pin
moredip10-Dec-04 7:31
moredip10-Dec-04 7:31 
GeneralRe: CDC::BitBlt(...) - strange speed variations Pin
G. Steudtel10-Dec-04 7:52
G. Steudtel10-Dec-04 7:52 
GeneralRe: CDC::BitBlt(...) - strange speed variations Pin
moredip10-Dec-04 8:16
moredip10-Dec-04 8:16 
GeneralRe: CDC::BitBlt(...) - strange speed variations Pin
G. Steudtel10-Dec-04 9:10
G. Steudtel10-Dec-04 9:10 
GeneralRe: CDC::BitBlt(...) - strange speed variations Pin
moredip10-Dec-04 9:22
moredip10-Dec-04 9:22 
GeneralRe: CDC::BitBlt(...) - strange speed variations Pin
Jack Puppy10-Dec-04 11:37
Jack Puppy10-Dec-04 11:37 
GeneralRe: CDC::BitBlt(...) - strange speed variations Pin
moredip10-Dec-04 11:46
moredip10-Dec-04 11:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.