OpenEvent是一個函式,可以用來執行返回事件對象的句柄。
函式功能,函式原型,參數說明,返回值,VB聲明,參數表,Remarks,
函式功能
打開一個已經存在的命名事件對象
函式原型
HANDLEOpenEvent(
DWORD dwDesiredAccess,
BOOL bInheritHandle,
LPCTSTR lpName
);
參數說明
該參數必須設定為以下值:
EVENT_ALL_ACCESS 指定事件對象所有可能的許可權
bInheritHandle 【in】指定是否返回的句柄是否繼承 。該參數必須設定為false
lpName 【in】指向一個以null結束的字元串,即將要打開的事件對象的名字。名稱是區分大小寫的。
返回值
函式執行成功則返回事件對象的句柄;失敗則返回NULL,獲取錯誤信息可以使用GetLastError.
VB聲明
Declare Function OpenEvent Lib "kernel32" Alias "OpenEventA" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal lpName As String) As Long
參數表
參數表 | ||
參數 | 類型及說明 | |
dwDesiredAccess | Long,下述常數之一: | |
EVENT_ALL_ACCESS | 要求對事件對象進行完全訪問 | |
EVENT_MODIFY_STATE | 允許SetEvent 和 ResetEvent函式 | |
SYNCHRONIZE | 允許事件對象的使用同步 | |
bInheritHandle | Long,如希望子進程能夠繼承句柄,則為TRUE | |
lpName | String,指定要打開的對象的名字 | |
註解 | ||
一旦不再需要,注意一定要用CloseHandle關閉事件句柄。如對象的所有句柄都已關閉,那么對象也會刪除 |
Remarks
The OpenEvent function enables multiple processes to open handles of the same event object. The function succeeds only if some process has already created the event using the CreateEvent function. The calling process can use the returned handle in any function that requires a handle to an event object, subject to the limitations of the access specified in the dwDesiredAccess parameter.
Use the DuplicateHandle function to duplicate the handle. Use the CloseHandle function to close the handle. The system closes the handle automatically when the process terminates. The event object is destroyed when its last handle has been closed.