Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Urgent !!! - Using WaitForMultipleObjects with VB6

131 views
Skip to first unread message

elad

unread,
May 12, 2002, 12:58:20 PM5/12/02
to
Hi

I'm trying to monitor changes in several different directories and I'm
trying to use WaitForMultipleObjects, Is it possible in VB ?
According to MSDN one of the argument is "Pointer to an array of
object handles" but how do I send ( In VB ) a pointer to array to the
API function?
I tried to change the declaration to be Byref and tried several ways
when calling the function but I'm getting errors,

Can you please guide me what do I need to do or send a full example
using this function.

Thanks a lot,
Elad

Tom Esh

unread,
May 12, 2002, 1:12:01 PM5/12/02
to
On 12 May 2002 09:58:20 -0700, elad.f...@comverse.com (elad)
wrote:

Just declare the lpHandles arg ByRef (omit ByVal) As Long and pass the
first element in the call. What actually gets passed is the address of
the first element, which as far as the Api is concerned is the address
of the array.

Declare Function WaitForMultipleObjects Lib "kernel32" (ByVal nCount
As Long, lpHandles As Long, ByVal bWaitAll As Long, ByVal
dwMilliseconds As Long) As Long


'usage...
'... Where lHandles is an array of Longs...

Ret = WaitForMultipleObjects(_ncount_, lHandles(0), _bWaitAll_,
_dwMilliseconds_)


-Tom
(please post replies to the newsgroup)

elad

unread,
May 13, 2002, 5:18:39 AM5/13/02
to
Thanks it's works.

But now I have a new problem, I'm trying to monitor directories being
created \ deleted under a drive (lets say M:\), The directories are
Views that being created by ClearCase ), It's monitor works on other
drives when creating or copying new directory but not on M:\ drive,

Any idea how can I fix that ?

Elad

Tom Esh

unread,
May 13, 2002, 11:54:27 AM5/13/02
to
On 13 May 2002 02:18:39 -0700, elad.f...@comverse.com (elad)
wrote:

I presume the objects you're waiting for were created with
FindFirst[Next]ChangeNotification (?). If so I believe it works with
logical drives as well as physical, though I don't have a way to test
it at the moment. No idea what ClearCase is, but if it's just creating
directories it shouldn't be a problem. On the other hand if it's
creating shell namespace objects or dirs with weird attributes it
might be.

elad

unread,
May 14, 2002, 7:00:01 AM5/14/02
to
Hi

Again thanks a lot for your help...
1. Do you have a full working example of using WaitForMultipleObjects
with VB 6 ?

2. When WaitForMultipleObjects indicate that there was a change it's
activate a function in VB that do something ( It doesn't metter what )
How can I still continue monitor changes while this function is
running ?

Elad.

Tom Esh

unread,
May 14, 2002, 12:01:08 PM5/14/02
to
On 14 May 2002 04:00:01 -0700, elad.f...@comverse.com (elad)
wrote:

>Again thanks a lot for your help...
>1. Do you have a full working example of using WaitForMultipleObjects
>with VB 6 ?
Not really. I've played with it enough to know it works, but just so
happens WaitForSingleObject has always been adequate in the end.
Maybe try AllApi:
http://www.allapi.net/agnet/index.php

>2. When WaitForMultipleObjects indicate that there was a change it's
>activate a function in VB that do something ( It doesn't metter what )
>How can I still continue monitor changes while this function is
>running ?

Typically unless you call it in a separate thread (i.e. activex exe),
you can't afford to tie up your app waiting indefinitely. The solution
is to use a timer (VB or Api) to periodically call WaitFor_ with a
very small (or even 0) timeout. In effect you don't really wait at
all, but rather use it as a means to ~test~ the signaled state.

If it helps, here's the timer proc snip from a dll I did. It uses
WaitForSingleObject, but the general idea would be the same:

Friend Sub WaitTimer()
Dim lRet As Long
Dim bCancel As Boolean
Static bBusy As Boolean

'prevent re-entry...
If bBusy Then Exit Sub '================>>>
bBusy = True

lRet = WaitForSingleObject(m_hNotifObj, 0&)
Select Case lRet
Case WAIT_TIMEOUT
bBusy = False
Exit Sub '(keep waiting) ================>>>
Case WAIT_OBJECT_0 'signaled!
RaiseEvent StatusChange(0, bCancel)
If bCancel Then
CancelWatch
Else 'keepwaiting(default)
FindNextChangeNotification m_hNotifObj
End If
Case Else 'WAIT_FAILED
RaiseEvent StatusChange(Err.LastDllError, bCancel)
CancelWatch
End Select
bBusy = False
End Sub

0 new messages