Function Description: Creates or opens a named or unknown event object. Function prototype: Handle createevent ( Lpsecurity_attributes lpeventattributes, // Security Attribute Bool bmanualreset, // reset mode Bool binitialstate, // initial state Lptstr lpname // Object Name ); Parameters: Lpeventattributes: [Input] a pointer to the security_attributes structure to determine whether the returned handle can be inherited by the quilt process. If lpeventattributes is null, this handle cannot be inherited. Windows NT/2000: the members in the lpeventattributes structure specify a security token for the new event. If lpeventattributes is null, the event will get a default security token. Bmanualreset: [Input] specify whether to manually restore or automatically restore the event object. If it is true, you must use the resetevent function to manually restore the event state to the stateless state. If this parameter is set to false, when an event is released by a waiting thread, the system automatically restores the event status to the stateless state. Binitialstate: [Input] specifies the initial status of the event object. If this parameter is set to true, the initial state is a signal state; otherwise, the initial state is a signal state. Lpname: [Input] The name of the specified event object. It is a string pointer that ends with 0. The character format of the name is limited to max_path. The name is case sensitive. If the name specified by lpname is the same as the name of an existing named event object, the function requests event_all_access to access the existing object. At this time, because the bmanualreset and binitialstate parameters have been set in the event creation process, these two parameters will be ignored. If lpeventattributes is a parameter that is not null, it determines whether the handle can be inherited, but its security descriptor members are ignored. If lpname is null, an unknown event object is created. If the lpname is the same as an existing signal, mutex, wait timer, job, or file ing object name, the function will fail and error_invalid_handle will be returned in the getlasterror function. This is because these objects share the same namespace. Terminal Services: you can add a prefix of "global/" or "Local/" to the name to create an object in a global or transaction namespace. In addition to the backslash (/), other parts of the name can use any character. For more information, see Kernel Object Name spaces. Windows 2000: in Windows 2000, no terminal service is running, and the prefix "Global/" and "Local/" will be ignored. In addition to the backslash (/), other parts of the name can use any character. Windows NT 4.0 and earlier versions, Windows 95/98: Except for the backslash (/), the name can contain any character. Return Value: If the function is successfully called, the function returns the handle of the event object. If the named object has been created before the function is called, the function returns the handle of the existing event object and returns error_already_exists in the getlasterror function. If the function fails, the return value is null. To obtain detailed error information, call getlasterror. Note: Call the handle returned by the createevent function. The handle has the event_all_access permission to access the new event object. It can also be used in any function with the event object handle. During the call process, all threads can specify the event object handle in a waiting function. When the status of the specified object is set to a signal state, a single object waits for the function to return. For the multi-object wait function, you can specify any or all specified objects to be set to a signal state. When the function is returned, the waiting thread is released to continue running. The initial status is set in the binitialstate parameter. Use the setevent function to set the event object status to a signal state. Use the resetevent function to set the event object state to the non-signal state. When the status of a manually restored event object is set to a signal state, the state of the object remains a signal State until it is explicitly called by the resetevent function. When the event object is set to a signal state, any number of waiting threads and threads that start to wait will be released. When the status of an automatically restored event object is set to a signal state, the state of the object remains a signal State until a waiting thread is released; the system automatically sets this function to the unsigned state. If no waiting thread is waiting, the status of the event object remains signaled. Multiple processes can hold multiple handles of the same event object. You can use this object to synchronize processes. The following object sharing mechanism is feasible: · In the createevent function, when the lpeventattributes parameter specifies that the handle can be inherited, the event object handle inherited by the child process created through the CreateProcess function. · A process can specify the event object handle in the duplicatehandle function to obtain a copy handle, which can be used by other processes. · A process can specify a name in the openevent or createevent function to obtain a famous event object handle. Use the closehandle function to close the handle. When a process stops, the system automatically closes the handle. When the last handle is closed, the event object is destroyed. Environment: Windows NT/2000: Version 3.1 or later is required Windows 95/98: Windows 95 or later Header file: It is defined in WINBASE. h; it must contain windows. h. Import to database: user32.lib UNICODE: in Windows NT/2000, it is executed in Unicode and ANSI. After an event is created, you can use the openevent () API to obtain its handle, and use closehandle () To close it, use setevent () or pulseevent () to set it to make it signal, use resetevent () To make it non-signal, use waitforsingleobject () or waitformultipleobjects () to wait It becomes a signal. Pulseevent () is an interesting method to use. Just like the name of this API, it makes an event The state of an object changes in a pulse, from no signal to no signal and then to no signal, and the entire operation is atomic. For the event object that is automatically reset, it only releases the first thread that waits for the event (if any), and Manually reset the event object, which releases all waiting threads. |