Class WindowsForeignFunctions
java.lang.Object
oshi.ffm.ForeignFunctions
oshi.ffm.windows.WindowsForeignFunctions
- Direct Known Subclasses:
Advapi32FFM, IPHlpAPIFFM, Kernel32FFM, PsapiFFM
Utility class for working with the Foreign Function and Memory API. Provides helpers for library lookup, downcalls,
and UTF-16 string conversion.
-
Field Summary
Fields inherited from class ForeignFunctions
CAPTURE_CALL_STATE, CAPTURED_STATE_LAYOUT, ERRNO_HANDLE, LIBRARY_ARENA, LINKER, SYMBOL_LOOKUP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcheckSuccess(int rc, int... allowedErrors) Validates a Windows API return code, allowingERROR_SUCCESSor specified codes.static booleanisSuccess(int winBool) Converts a Windows BOOL (0 or non-zero) to a Java boolean.static StringreadAnsiString(MemorySegment seg, int maxLen) Reads a null-terminated ANSI (single-byte) string from the given memory segment.static StringReads a null-terminated UTF-16 wide string from the given memory segment.static MemorySegmentsetupTokenPrivileges(Arena arena, MemorySegment luid) Creates and initializes aTOKEN_PRIVILEGESstructure with one privilege enabled.static MemorySegmenttoWideString(Arena arena, String s) Converts a Java string into a null-terminated UTF-16LE wide string memory segment.Methods inherited from class ForeignFunctions
downcall, getByteArrayFromNativePointer, getErrno, getStringFromNativePointer, getStructFromNativePointer, lib, libraryLookup
-
Constructor Details
-
WindowsForeignFunctions
protected WindowsForeignFunctions()
-
-
Method Details
-
checkSuccess
public static int checkSuccess(int rc, int... allowedErrors) Validates a Windows API return code, allowingERROR_SUCCESSor specified codes.- Parameters:
rc- return code from a Windows API callallowedErrors- optional additional codes- Returns:
- the original code if valid
- Throws:
Win32Exception- if not successful
-
isSuccess
public static boolean isSuccess(int winBool) Converts a Windows BOOL (0 or non-zero) to a Java boolean. In Windows API, 0 means FALSE and non-zero means TRUE.- Parameters:
winBool- the BOOL value returned by a Windows API- Returns:
trueif non-zero,falseif zero
-
readWideString
Reads a null-terminated UTF-16 wide string from the given memory segment.- Parameters:
seg- the memory segment containing the UTF-16 string- Returns:
- the decoded Java string
-
readAnsiString
Reads a null-terminated ANSI (single-byte) string from the given memory segment.- Parameters:
seg- the memory segment containing the ANSI stringmaxLen- the maximum number of bytes to read- Returns:
- the decoded Java string
-
setupTokenPrivileges
Creates and initializes aTOKEN_PRIVILEGESstructure with one privilege enabled.- Parameters:
arena- the memory arena used for allocationluid- the LUID of the privilege to enable- Returns:
- a memory segment containing the initialized
TOKEN_PRIVILEGESstructure
-
toWideString
Converts a Java string into a null-terminated UTF-16LE wide string memory segment.- Parameters:
arena- the memory arena used for allocations- the Java string to convert- Returns:
- a memory segment containing the UTF-16LE encoded string with a null terminator
-