delphi - Infinity loop on Message Queue -


i'm working injected dll inside process. in dll create 1 thread among other things set 2 timers , keyboardhook (setwindowshookex wh_keyboard_ll)... make hook , 2 timers work, needed create 1 message pump procedure. , call message pump last thing on thread, can see in thread.execute:

procedure mymainthread.execute; begin   while not terminated     begin       mythread:= self;       startkeyboardhook;       startup;       settimer(0, 0, 60000, @mymainthread.contacthome);       settimer(0, 0, 40000, @mymainthread.mapproc);          createmessagepump;       terminate;     end; end; 

ok, after createmessagepump call, terminate, because believe message pump 1 infinity loop, , if out that, wrong occurs need terminate thread. createmessagepump on this:

procedure mymainthread.createmessagepump; var   appmsg: tmsg; begin   while getmessage(appmsg, 0, 0, 0)     begin       translatemessage(appmsg);       dispatchmessage(appmsg);     end;   //if needed quit procedure use postquitmessage(0); end; 

i'm doing correct way? mean, correct believe loop infinite?

the loop in execute method pointless. since final act of loop body call terminate loop body can run once. write this:

procedure mymainthread.execute; begin   mythread:= self;   startkeyboardhook;   startup;   settimer(0, 0, 60000, @mymainthread.contacthome);   settimer(0, 0, 40000, @mymainthread.mapproc);      createmessagepump; end; 

your message loop fine. people may warn check return value of getmessage more closely, usage fine. see raymond's discussion of topic: http://blogs.msdn.com/b/oldnewthing/archive/2013/03/22/10404367.aspx


it's not clear, seems plausible passing timer procedure not compatible required function signature. declaration of settimer in windows unit results in no type checking being performed on callback pass. means can pass absolutely anything. fact compiler compels use @ operator warning sign have problem.

the way out stop using @ operator, , use fixed declaration of settimer. should use code sertac provided in 1 of earlier questions: using process32first/next inside dll procedure.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -