Wait for Event

Hi, im developing a active X dll in visual basic 6 , in one of my DLL functions i just want to wait for a com event to be raised so i can return a value of my principal function, i just dont know if there is any function like WaitForEvent to keep my fucntion waiting for the event. Hope someone can help me. Thanks

Comments

  • [b][red]This message was edited by BitByBit_Thor at 2007-3-31 4:56:29[/red][/b][hr]
    : Hi, im developing a active X dll in visual basic 6 , in one of my DLL functions i just want to wait for a com event to be raised so i can return a value of my principal function, i just dont know if there is any function like WaitForEvent to keep my fucntion waiting for the event. Hope someone can help me. Thanks
    :

    There is a bit of a clumsy VB-native way:
    *choir starts to sing*
    DoEvents

    What it does is 'halt execution' for a bit and return control back to Windows: all other apps get a chance to read and handle their message queue's.
    This includes the current app! Meaning that when this function is called for example when clicking a button, if the user has in the mean time clicked another button then this click will be handled first before execution is returned to your function. Meaning you're actually doing a sort of 'multi-threading'! This can cause problems if the calling program does not account for it (for example, setting Me.Enabled = False, will prvent this sort of thing from happening).

    This is how it would look in your function.
    [code]
    Function ComFunction(SomethingHere) As SomeReturn
    ...
    'Wait for message
    Do
    'Make sure we don't take up 100% processing power
    ' in this loop. Effectively, it'll be around 20-50%.
    'And less when there is another program using the processor
    DoEvents
    Loop Until [italic]EventHasBeenRaised[/italic] [b]Or[/b] _
    [italic]TimeOutHasExpired[/italic]
    ...
    End Function
    [/code]
    [italic]TimeOutHasExpired[/italic] is quite important to have. You need to make sure you're not staying stuck in that loop forever.

    All in all, this doesn't seem like a good way to do it in a DLL.


    I have a question though: can a DLL receive events?

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories