2 Replies - 1219 Views - Last Post: 31 May 2010 - 01:12 PM Rate Topic: -----

#1 mejicano  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-July 09

Subclassing & Delay

Posted 31 May 2010 - 11:54 AM

Hello Guys,

im having a really strange problem.

im using a c++ dll to hook into an extern application. there i do subclass 2 labels.

with every WM_SETTEXT posted to one of the labels, an event in my app is raised and i retrieve the current text. so far it works prefectly, no problems.

the problem ocurres when i try to let my application do a break.
when the event is raised i know that the label's content is refreshed. but depending with the label, some other details on the extern form application get changed.
but these changes (animations) happen a little bit later, than my receive_event is raised.

for using my event as a signal to take a snapshot of the extern form i need to pause my application for some miliseconds (i guess). because while my code is waiting the extern program updates their form. when the update is done, its the right moment for me to take the snapshot.

these are my simple thoughts to make it work... but it doesnt seem that easy.

i tried Threading.Thread.Sleep and
    Private Sub Delay(ByVal dblSecs As Double)
        Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
        Dim dblWaitTil As Date

        Now.AddSeconds(OneSec)
        dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(dblSecs)
        Do Until Now > dblWaitTil
            Application.DoEvents() ' Allow windows messages to be processed
        Loop
    End Sub
 


and even others. what happens is always the same:

while im delaying my application (when the receive_event is just raised) the extern form is frozen... as long as my app is in the delay. exactly when my app leaves the delay function, the extern form starts working again too, and all changes are done at once.


so the only thing i achieved is having a break in both, the extern app and mine. thats useless to me!


it seems like everything i do with the thread or process (idk, im not really concerned about hooks) is done with the hooked application too. although i just subclassed 2 labels of it.


maybe it is a common mistake im making, or im just not seeing something!

i didnt provide much code because i dont know what exactly u'd like to see. but i give u all u'd like to see immediatly. the class i use to hook is attached.


i hope anyone can tell me what to do, or at least point me in the right direction.

thousand thanks!



denis :)

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Subclassing & Delay

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Subclassing & Delay

Posted 31 May 2010 - 12:39 PM

And I assume there is no other time the DLL can raise an event? The problem really is that the DLL should have only caused the event to be raised at the end of its full update (after the animations). But I guess you will have to work around that.

It sounds like the problem is that when you put the thread to sleep, the other application is also on that thread and sleeps. So I would try using something like a timer instead of sleeping the thread. The raised event would kick off your timer, it waits and then takes a snapshot of the external app.

Again, it is not the cleanest solution and I would have tried seeing if I could have the DLL raise your VB event at the end of its full update cycle. That way your VB app doesn't have to wait. By the time it gets the event, the external app is ready to go for a snapshot.

But try a timer and see if that helps you out. :)
Was This Post Helpful? 0
  • +
  • -

#3 mejicano  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-July 09

Re: Subclassing & Delay

Posted 31 May 2010 - 01:12 PM

hey, thanks for ur reply...


yes, u are right. i cant influence when the event is raised nor receive another one. because im depending in the controls of the subclassed events of the extern application.

i would love to have a single & safe event that i can rely on...
do u know if there is a special message that is posted to a window to "refresh" or "update" ?

Quote

It sounds like the problem is that when you put the thread to sleep, the other application is also on that thread and sleeps. So I would try using something like a timer instead of sleeping the thread. The raised event would kick off your timer, it waits and then takes a snapshot of the external app.


yes, i assumed the same. thats why i tried a 'normal' delay, that is not working for the whole thread (afaik).

    Private Sub Delay(ByVal dblSecs As Double)
        Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
        Dim dblWaitTil As Date

        Now.AddSeconds(OneSec)
        dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(dblSecs)
        Do Until Now > dblWaitTil
            Application.DoEvents() ' Allow windows messages to be processed
        Loop
    End Sub



this shouldnt take effect on the whole thread. but this and the normal timer version let the applications still freeze.
i could play around a little bit more with the 'real timer' option.. but as far as i went, it effects the same :(


any more ideas?

Thanks for contribution :)


denis
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1