Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #5666

extremally important question (on how winapi program works)

Newsgroups comp.programming
Date 2015-08-29 15:23 -0700
Message-ID <02f97a5e-ee71-4437-966b-4feb3f06d45f@googlegroups.com> (permalink)
Subject extremally important question (on how winapi program works)
From fir <profesor.fir@gmail.com>

Show all headers | View raw


This is extremally important question to me, though i doubt if many people are able to fully answer this, lets see 

assume you got winapi classic WinMain() 
app (like small game drawing by gdi, something like that) 

you got a loop there 

for(;;) 
  { 
     GameStateProcessing(); 
     MessagePump(); 
     Sleep(10); 
  } 

you do your game data processing, 
then call message pump classic code 
(mine looks like that 

    for(;;) 
    { 
        /* EVENTS 
         */ 

        static int done = 0; 

        MSG msg; 

        while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) 

         if(!GetMessage(&msg, NULL, 0,0)) done = 1; 
         else 
           TranslateMessage(&msg), 
           DispatchMessage(&msg); 

        if(done) break; 

      //......... 
   } 

then yet you have a sleep 
(may assume for example that game processing takes 10 ms, message pump part probably is quick so, all loop 'turn' takes 20 ms so game works at 50 Hz) 

THE TWO IMPORTANT QUESTIONS 

1) I got WndProcedure callback with my own code there.. May I assume that this procedure is called by the MessagePump part (though indirectly i call some api call, which calls my callback back) ? 

Which one api call executes it? (I mean which api call executes my callback) 
Is it Dispatchmessage()? 

2) Not only my ap but System needs 
to be handled too.. If so i thing something that i may call virtually 
SystemDoYourOwnWorkForAWhileThenBack() 
must be called regurally and i wonder 
when it is called.. (what rules plays here) 

I wonder if this something like preempting my app by bruteforce (by freezing by some interrupt in half of the routines)  in regular time periods base (I do not notice such behaviour when i measure frame times by timer) 
or this is maybe done when i call 
Sleep() - (Sleep could be potentially 
used here i think, but i dont know how it works), (or maybe some message pump appi takes opportunity that app regullary gives avay cpu for a while then do some system work there?) 

what if some app do not call Sleep? 
Then all cpu would be consumed and 
if no MessagePump would call system task it would have to be preempted by force 
(but i am only speculating here) 
How it is done? 

TNX 

Back to comp.programming | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

extremally important question (on how winapi program works) fir <profesor.fir@gmail.com> - 2015-08-29 15:23 -0700
  Re: extremally important question (on how winapi program works) "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-08-30 09:18 +0200
    Re: extremally important question (on how winapi program works) fir <profesor.fir@gmail.com> - 2015-08-30 03:48 -0700
      Re: extremally important question (on how winapi program works) "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-08-30 15:12 +0200
        Re: extremally important question (on how winapi program works) fir <profesor.fir@gmail.com> - 2015-08-30 13:38 -0700
          Re: extremally important question (on how winapi program works) "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-08-31 09:49 +0200
            Re: extremally important question (on how winapi program works) Chad <cdalten@gmail.com> - 2015-08-31 16:46 -0700

csiph-web