📄 kernel32.java
字号:
* HANDLE FindFirstChangeNotification(
* LPCTSTR lpPathName,
* BOOL bWatchSubtree,
* DWORD dwNotifyFilter
* );
*
* Parameters
*
* lpPathName
* [in] Pointer to a null-terminated string that specifies the path of the directory to watch.
*
* In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.
*
* Windows Me/98/95: This string must not exceed MAX_PATH characters.
*
* bWatchSubtree
* [in] Specifies whether the function will monitor the directory or the directory tree. If this parameter is TRUE, the function monitors the directory tree rooted at the specified directory; if it is FALSE, it monitors only the specified directory.
* dwNotifyFilter
* [in] Filter conditions that satisfy a change notification wait. This parameter can be one or more of the following values.
* Value Meaning
* FILE_NOTIFY_CHANGE_FILE_NAME Any file name change in the watched directory or subtree causes a change notification wait operation to return. Changes include renaming, creating, or deleting a file name.
* FILE_NOTIFY_CHANGE_DIR_NAME Any directory-name change in the watched directory or subtree causes a change notification wait operation to return. Changes include creating or deleting a directory.
* FILE_NOTIFY_CHANGE_ATTRIBUTES Any attribute change in the watched directory or subtree causes a change notification wait operation to return.
* FILE_NOTIFY_CHANGE_SIZE Any file-size change in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change in file size only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.
* FILE_NOTIFY_CHANGE_LAST_WRITE Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change to the last write-time only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.
* FILE_NOTIFY_CHANGE_SECURITY Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return.
*
* Return Value
*
* If the function succeeds, the return value is a handle to a find change notification object.
*
* If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
* </pre>
* @throws IllegalAccessException
* @throws NativeException
*/
public static final HANDLE FindFirstChangeNotification(String lpPathName, boolean bWatchSubtree, DWORD dwNotifyFilter) throws NativeException, IllegalAccessException {
JNative FindFirstChangeNotification = new JNative(DLL_NAME, "FindFirstChangeNotificationA");
FindFirstChangeNotification.setRetVal(Type.INT);
FindFirstChangeNotification.setParameter(0, lpPathName);
FindFirstChangeNotification.setParameter(1, bWatchSubtree ? -1 : 0);
FindFirstChangeNotification.setParameter(2, dwNotifyFilter.getValue());
FindFirstChangeNotification.invoke();
return new HANDLE(FindFirstChangeNotification.getRetValAsInt());
}
/**
* <h3>FindNextChangeNotification</h3>
* <pre>
*
*
* The FindNextChangeNotification function requests that the operating system signal a change notification handle the next time it detects an appropriate change.
*
* BOOL FindNextChangeNotification(
* HANDLE hChangeHandle
* );
*
* Parameters
*
* hChangeHandle
* [in] Handle to a change notification handle created by the FindFirstChangeNotification function.
*
* Return Value
*
* If the function succeeds, the return value is nonzero.
*
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
* Remarks
*
* After the FindNextChangeNotification function returns successfully, the application can wait for notification that a change has occurred by using the wait functions.
*
* If a change occurs after a call to FindFirstChangeNotification but before a call to FindNextChangeNotification, the operating system records the change. When FindNextChangeNotification is executed, the recorded change immediately satisfies a wait for the change notification.
*
* FindNextChangeNotification should not be used more than once on the same handle without using one of the wait functions. An application may miss a change notification if it uses FindNextChangeNotification when there is a change request outstanding.
*
* When hChangeHandle is no longer needed, close it by using the FindCloseChangeNotification function.
* </pre>
* @return true if the function call succeed
* @throws NativeException
* @throws IllegalAccessException
*/
public static final boolean FindNextChangeNotification(HANDLE hChangeHandle) throws NativeException, IllegalAccessException {
JNative FindNextChangeNotification = new JNative(DLL_NAME, "FindNextChangeNotification");
FindNextChangeNotification.setRetVal(Type.INT);
FindNextChangeNotification.setParameter(0, hChangeHandle.getValue());
FindNextChangeNotification.invoke();
return FindNextChangeNotification.getRetValAsInt() == 0;
}
/**
* <h3>FindCloseChangeNotification</h3>
* <pre>
*
* The FindCloseChangeNotification function stops change notification handle monitoring.
*
* BOOL FindCloseChangeNotification(
* HANDLE hChangeHandle
* );
*
* Parameters
*
* hChangeHandle
* [in] Handle to a change notification handle created by the FindFirstChangeNotification function.
*
* Return Values
*
* If the function succeeds, the return value is nonzero.
*
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
* </pre>
* @return true if the function call succeed
* @throws IllegalAccessException
* @throws NativeException
*/
public static final boolean FindCloseChangeNotification(HANDLE hChangeHandle) throws NativeException, IllegalAccessException {
JNative FindCloseChangeNotification = new JNative(DLL_NAME, "FindCloseChangeNotification");
FindCloseChangeNotification.setRetVal(Type.INT);
FindCloseChangeNotification.setParameter(0, hChangeHandle.getValue());
FindCloseChangeNotification.invoke();
return FindCloseChangeNotification.getRetValAsInt() == 0;
}
/**
* <h3>WaitForSingleObjectEx</h3>
* <pre>
*
* Waits until the specified object is in the signaled state, an I/O completion routine or asynchronous procedure call (APC) is queued to the thread, or the time-out interval elapses.
*
* To wait for multiple objects, use the WaitForMultipleObjectsEx.
*
* DWORD WINAPI WaitForSingleObjectEx(
* HANDLE hHandle,
* DWORD dwMilliseconds,
* BOOL bAlertable
* );
*
* Parameters
*
* hHandle
* [in] A handle to the object. For a list of the object types whose handles can be specified, see the following Remarks section.
*
* If this handle is closed while the wait is still pending, the function's behavior is undefined.
*
* The handle must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.
* dwMilliseconds
* [in] The time-out interval, in milliseconds. The function returns if the interval elapses, even if the object's state is nonsignaled and no completion routines or APCs are queued. If dwMilliseconds is zero, the function tests the object's state and checks for queued completion routines or APCs and then returns immediately. If dwMilliseconds is INFINITE, the function's time-out interval never elapses.
* bAlertable
* [in] If this parameter is TRUE and the thread is in the waiting state, the function returns when the system queues an I/O completion routine or APC, and the thread runs the routine or function. Otherwise, the function does not return, and the completion routine or APC function is not executed.
*
* A completion routine is queued when the ReadFileEx or WriteFileEx function in which it was specified has completed. The wait function returns and the completion routine is called only if bAlertable is TRUE, and the calling thread is the thread that initiated the read or write operation. An APC is queued when you call QueueUserAPC.
*
* Return Value
*
* If the function succeeds, the return value indicates the event that caused the function to return. It can be one of the following values.
* Return code/value Description
* WAIT_ABANDONED
* 0x00000080L The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.
*
* If the mutex was protecting persistent state information, you should check it for consistency.
* WAIT_IO_COMPLETION
* 0x000000C0L The wait was ended by one or more user-mode asynchronous procedure calls (APC) queued to the thread.
* WAIT_OBJECT_0
* 0x00000000L The state of the specified object is signaled.
* WAIT_TIMEOUT
* 0x00000102L The time-out interval elapsed, and the object's state is nonsignaled.
*
* If the function fails, the return value is WAIT_FAILED ((DWORD)0xFFFFFFFF). To get extended error information, call GetLastError.
*
* </pre>
* <h4>Remarks</h4>
* <pre>
* The WaitForSingleObjectEx function determines whether the wait criteria have been met. If the criteria have not been met, the calling thread enters the wait state until the conditions of the wait criteria have been met or the time-out interval elapses.
*
* The function modifies the state of some types of synchronization objects. Modification occurs only for the object whose signaled state caused the function to return. For example, the count of a semaphore object is decreased by one.
*
* The WaitForSingleObjectEx function can wait for the following objects:
*
* Change notification
* Console input
* Event
* Memory resource notification
* Mutex
* Process
* Semaphore
* Thread
* Waitable timer
*
* Use caution when calling the wait functions and code that directly or indirectly creates windows. If a thread creates any windows, it must process messages. Message broadcasts are sent to all windows in the system. A thread that uses a wait function with no time-out interval may cause the system to become deadlocked. Two examples of code that indirectly creates windows are DDE and the CoInitialize function. Therefore, if you have a thread that creates windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather than WaitForSingleObjectEx.
* </pre>
* @throws IllegalAccessException
* @throws NativeException
*/
public static final int WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, boolean bAlertable) throws NativeException, IllegalAccessException {
if(WaitForSingleObjectEx == null) {
WaitForSingleObjectEx = new JNative(DLL_NAME, "WaitForSingleObjectEx");
WaitForSingleObjectEx.setRetVal(Type.INT);
}
WaitForSingleObjectEx.setParameter(0, hHandle.getValue());
WaitForSingleObjectEx.setParameter(1, dwMilliseconds.getValue());
WaitForSingleObjectEx.setParameter(2, bAlertable ? -1 : 0);
WaitForSingleObjectEx.invoke();
return WaitForSingleObjectEx.getRetValAsInt();
}
private static JNative WaitForSingleObjectEx = null;
/**
* <h3>WaitForMultipleObjectsEx</h3>
<pre>
Waits until one or all of the specified objects are in the signaled state, an I/O completion routine or asynchronous procedure call (APC) is queued to the thread, or the time-out interval elapses.
DWORD WINAPI WaitForMultipleObjectsEx(
DWORD nCount,
const HANDLE* lpHandles,
BOOL bWaitAll,
DWORD dwMilliseconds,
BOOL bAlertable
);
Parameters
nCount
[in] The number of object handles to wait for in the array pointed to by lpHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS.
lpHandles
[in] An array of object handles. For a list of the object types whose handles can be specified, see the following Remarks section. The array can contain handles of objects of different types. It may not contain the multiple copies of the same handle.
If one of these handles is closed while the wait is still pending, the function's behavior is undefined.
The handles must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.
Windows Me/98/95: No handle may be a duplicate of another handle created using DuplicateHandle.
bWaitAll
[in] If this parameter is TRUE, the function returns when the state of all objects in the lpHandles array is set to signaled. If FALSE, the function returns when the state of any one of the objects is set to signaled. In the latter case, the return value indicates the object whose state caused the function to return.
dwMilliseconds
[in] The time-out interval, in milliseconds. The function returns if the interval elapses, even if the criteria specified by the bWaitAll parameter are not met and no completion routines or APCs are queued. If dwMilliseconds is zero, the function tests the states of the specified objects and checks for queued completion routines or APCs and then returns immediately. If dwMilliseconds is INFINITE, the function's time-out interval never elapses.
bAlertable
[in] If this parameter is TRUE, the function returns when the system queues an I/O completion routine or APC, and the thread runs the routine or function. If this parameter is FALSE, the function does not return and the completion routine or APC function is not executed.
A completion routine is queued when the ReadFileEx or WriteFileEx function in which it was specified has completed. The wait function returns and the completion routine is called only if bAlertable is TRUE and the calling thread is the thread that initiated the read or write operation. An APC is queued when you call QueueUserAPC.
Return Value
If the function succeeds, the return value indicates the event that caused the function to return. It can be one of the following values. (Note that WAIT_OBJECT_0 is defined as 0 and WAIT_ABANDONED_0 is defined as 0x00000080L.)
Return code/value Description
WAIT_OBJECT_0 to (WAIT_OBJECT_0 + nCount– 1) If bWaitAll is TRUE, the return value indicates that the state of all specified objects is signaled.
If bWaitAll is FALSE, the return value minus WAIT_OBJECT_0 indicates the lpHandles array index of the object that satisfied the wait. If more than one object became signaled during the call, this is the array index of the signaled object with the smallest index value of all the signaled objects.
WAIT_ABANDONED_0 to (WAIT_ABANDONED_0 + nCount– 1) If bWaitAll is TRUE, the return value indicates that the state of all specified objects is signaled, and at least one of the objects is an abandoned mutex object.
If bWaitAll is FALSE, the return value minus WAIT_ABANDONED_0 indicates the lpHandles array index of an abandoned mutex object that satisfied the wait. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.
If a mutex was protecting persistent state information, you should check it for consistency.
WAIT_IO_COMPLETION
0x000000C0L The wait was ended by one or more user-mode asynchronous procedure calls (APC) queued to the thread.
WAIT_TIMEOUT
0x00000102L The time-out interval elapsed, the conditions specified by the bWaitAll parameter were not satisfied, and no completion routines are queued.
If the function fails, the return value is WAIT_FAILED ((DWORD)0xFFFFFFFF). To get extended error information, call GetLastError.
</pre>
<h4>Remarks</h4>
<pre>
The WaitForMultipleObjectsEx function determines whether the wait criteria have been met. If the criteria have not been met, the calling th
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -