-
Feb 2nd, 2007, 12:51 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Why is CreateEvent Not Functioning Correctly
When I run the code below, the return value from WaitForSingleObjects is 0, despite the fact that I specified in CreateEvent for the initial state to be non-signaled. The code functions correctly if I uncomment the ResetEvent command (resulting in a return value of WAIT_TIMEOUT). The handle from CreateEvent is valid, but is not properly setting the initial state. Does anyone know why this might be happening?
VB Code:
Public Declare Function ResetEvent Lib "kernel32" (ByVal hEvent As Long) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA" (ByVal lpEventAttributes As Long, ByVal bManualReset As Long, ByVal bInitialState As Long, ByVal lpName As String) As Long
Private Sub test()
Dim hTest As Long
Dim lngRetVal As Long
hTest = CreateEvent(ByVal 0&, True, False, ByVal 0&)
'ResetEvent (hTest)
lngRetVal = WaitForSingleObject(hTest, 0)
If (lngRetVal = 0) Then
'Code Enters Here
Else
'Does Not Enter Here
End If
End Sub
Last edited by Joey_k29; Feb 5th, 2007 at 11:59 PM.
-
Feb 2nd, 2007, 10:20 AM
#2
Re: Why is CreateFile Not Functioning Correctly
I run your code and it always returns WAIT_TIMEOUT, with or without ResetEvent
-
Feb 2nd, 2007, 10:33 AM
#3
Thread Starter
Hyperactive Member
Re: Why is CreateFile Not Functioning Correctly
Jcis: Are you running VB6 in Windows XP SP2? So far I have only found one other instance on the web where someone had the same question on another forum (that went unanswered). He too was running it in Windows XP SP2.
I have tested both in the IDE and compiled form. Neither one is working for me. But as best as I can tell (and further confirmed by your success) there is nothing wrong with the code.
Thank you for your input.
-
Feb 2nd, 2007, 10:38 AM
#4
Re: Why is CreateFile Not Functioning Correctly
Originally Posted by Joey_k29
Jcis: Are you running VB6 in Windows XP SP2?
Yes, tested and works fine in 2 computers, both with Windows XP SP2 + VB6.
-
Feb 3rd, 2007, 01:31 AM
#5
Thread Starter
Hyperactive Member
Re: Why is CreateFile Not Functioning Correctly
Very odd. I don't know how to explain it. I tested other code where I created an event and reset it in the same function. In a later function, I called WaitForSingleObject with it, and it failed to wait indicating the event was set despite the fact that there was no code to set the event.
-
Feb 5th, 2007, 11:59 PM
#6
Thread Starter
Hyperactive Member
Re: Why is CreateFile Not Functioning Correctly
The problem I encountered is ByVal 0& is not correct as the last parameter in create event. Doing so results in a named event. vbNullString properly results in an unnamed event and solves my issue.
Thank you for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|