I need to pause process for 5 secunds. For this I try events but they works inproperly. May be you know why?
.data
MyEvent db "MyEvent", 0
hEvent dd ?
.code
start:
invoke CreateEvent, 0, 0, 0, offset MyEvent
mov hEvent, eax
invoke MessageBeep, MB_OK ; SystemDefault
invoke ResetEvent, hEvent
invoke WaitForSingleObject, hEvent, 5000
invoke ExitProcess, NULL
.data
MyEvent db "MyEvent", 0
hEvent dd ?
.code
start:
invoke CreateEvent, 0, 0, 0, offset MyEvent
mov hEvent, eax
invoke MessageBeep, MB_OK ; SystemDefault
invoke ResetEvent, hEvent
invoke WaitForSingleObject, hEvent, 5000
invoke ExitProcess, NULL
If you just need to pause for 5 seconds, do "invoke Sleep, 5000".
In your code example, you shouldn't have to ResetEvent - you're creating the even with initial state of unsignalled.
Is there any particular reason you're using a named event instead of just passing NULL for the eventname? Does the function fail?
Also, you ought to pass "NULL" as first argument, and FALSE as 2nd and 3rd. While the outcome is the same, it's a bit more "correct" programming, since the first argument is a pointer and 2nd and 3rd are booleans. Easier to see what's going on.
In your code example, you shouldn't have to ResetEvent - you're creating the even with initial state of unsignalled.
Is there any particular reason you're using a named event instead of just passing NULL for the eventname? Does the function fail?
Also, you ought to pass "NULL" as first argument, and FALSE as 2nd and 3rd. While the outcome is the same, it's a bit more "correct" programming, since the first argument is a pointer and 2nd and 3rd are booleans. Easier to see what's going on.
Not exactly. Sleep suspends the execution but I want only wait. MessageBeep needs a time to load wave file and play it. Now it cant do it because ExitProcess brakes the execution. I can write e.g.
invoke MessageBeep, ...
invoke MessageBox, ....
but in this case i need click OK or press Enter button to close message window. I want to hear beep without MessageBox and creating timers.
Mike
invoke MessageBeep, ...
invoke MessageBox, ....
but in this case i need click OK or press Enter button to close message window. I want to hear beep without MessageBox and creating timers.
Mike
Just exactly how does the event thingy fail?
Also, WaitForSingleObject ought to suspend execution, just like Sleep, while it's waiting for the event to be triggered (or for the timeout to occur).
Your best bet is probably to use a timer. Don't even think about coding a manual delay-loop.
Also, WaitForSingleObject ought to suspend execution, just like Sleep, while it's waiting for the event to be triggered (or for the timeout to occur).
Your best bet is probably to use a timer. Don't even think about coding a manual delay-loop.