Interface Kernel32

  • All Superinterfaces:
    com.sun.jna.AltCallingConvention, BaseTSD, com.sun.jna.Library, com.sun.jna.win32.StdCall, com.sun.jna.win32.StdCallLibrary, WinBase, Wincon, WinDef, WinNT

    public interface Kernel32
    extends com.sun.jna.win32.StdCallLibrary, WinNT, Wincon
    Interface definitions for kernel32.dll.
    Since:
    0.40
    • Field Detail

      • INSTANCE

        static final Kernel32 INSTANCE
        Instance.
    • Method Detail

      • GetStdHandle

        WinNT.HANDLE GetStdHandle​(int handle)
        Get a handle to specified standard device.
        Parameters:
        handle - The standard device identifier
        Returns:
        A handle to the specified standard device (standard input, output, or error)
      • SetStdHandle

        boolean SetStdHandle​(int std,
                             WinNT.HANDLE handle)
        Set a standard device handle.
        Parameters:
        std - The standard device identifier
        handle - The handle for the standard device
        Returns:
        True if successful, if False then use GetLastError() to get extended error information
        See Also:
        SetStdHandle documentation
      • CloseHandle

        boolean CloseHandle​(WinNT.HANDLE handle)
        Closes an open object handle.
        Parameters:
        handle - Handle to an open object. This parameter can be a pseudo handle or INVALID_HANDLE_VALUE.
        Returns:
        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.
        See Also:
        CloseHandle
      • SetLastError

        void SetLastError​(int code)
        Set a custom error code.
        Parameters:
        code - Error code to set
      • WriteFile

        boolean WriteFile​(WinNT.HANDLE handle,
                          byte[] buffer,
                          int count,
                          com.sun.jna.ptr.IntByReference written,
                          WinBase.OVERLAPPED overlapped)
        Writes data to the specified file or input/output (I/O) device.
        Parameters:
        handle - A handle to the file or I/O device (for example, a file, file stream, physical disk, volume, console buffer, tape drive, socket, communications resource, mailslot, or pipe).
        buffer - A pointer to the buffer containing the data to be written to the file or device.
        count - The number of bytes to be written to the file or device.
        written - A pointer to the variable that receives the number of bytes written when using a synchronous hFile parameter.
        overlapped - A pointer to an WinBase.OVERLAPPED structure is required if the hFile parameter was opened with FILE_FLAG_OVERLAPPED, otherwise this parameter can be NULL.
        Returns:
        If the function succeeds, the return value is nonzero (TRUE). If the function fails, or is completing asynchronously, the return value is zero (FALSE). To get extended error information, call the GetLastError function.
      • ReadFile

        boolean ReadFile​(WinNT.HANDLE handle,
                         byte[] buffer,
                         int count,
                         com.sun.jna.ptr.IntByReference read,
                         WinBase.OVERLAPPED overlapped)
        Reads data from the specified file or input/output (I/O) device. Reads occur at the position specified by the file pointer if supported by the device.
        Parameters:
        handle - A handle to the device (for example, a file, file stream, physical disk, volume, console buffer, tape drive, socket, communications resource, mailslot, or pipe).
        buffer - A pointer to the buffer that receives the data read from a file or device.
        count - The maximum number of bytes to be read.
        read - A pointer to the variable that receives the number of bytes read when using a synchronous hFile parameter
        overlapped - A pointer to an OVERLAPPED structure is required if the handle parameter was opened with FILE_FLAG_OVERLAPPED, otherwise it can be NULL.
        Returns:
        If the function succeeds, the return value is nonzero (TRUE). If the function fails, or is completing asynchronously, the return value is zero (FALSE).
      • CreateFile

        WinNT.HANDLE CreateFile​(String name,
                                int access,
                                int mode,
                                WinBase.SECURITY_ATTRIBUTES security,
                                int disposition,
                                int flags,
                                WinNT.HANDLE template)
        The CreateFile function creates or opens a file, file stream, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, or named pipe. The function returns a handle that can be used to access an object.
        Parameters:
        name - A pointer to a null-terminated string that specifies the name of an object to create or open.
        access - The access to the object, which can be read, write, or both.
        mode - The sharing mode of an object, which can be read, write, both, or none.
        security - A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpSecurityAttributes is NULL, the handle cannot be inherited.
        disposition - An action to take on files that exist and do not exist.
        flags - The file attributes and flags.
        template - Handle to a template file with the GENERIC_READ access right. The template file supplies file attributes and extended attributes for the file that is being created. This parameter can be NULL.
        Returns:
        If the function succeeds, the return value is an open handle to a specified file. If a specified file exists before the function call and dwCreationDisposition is CREATE_ALWAYS or OPEN_ALWAYS, a call to GetLastError returns ERROR_ALREADY_EXISTS, even when the function succeeds. If a file does not exist before the call, GetLastError returns 0 (zero). If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
      • GetEnvironmentVariable

        int GetEnvironmentVariable​(String name,
                                   char[] buffer,
                                   int size)
        Retrieves the contents of the specified variable from the environment block of the calling process.
        Parameters:
        name - The name of the environment variable.
        buffer - A pointer to a buffer that receives the contents of the specified environment variable as a null-terminated string. An environment variable has a maximum size limit of 32,767 characters, including the null-terminating character.
        size - The size of the buffer pointed to by the buffer parameter, including the null-terminating character, in characters.
        Returns:
        If the function succeeds, the return value is the number of characters stored in the buffer pointed to by buffer, not including the terminating null character. If buffer is not large enough to hold the data, the return value is the buffer size, in characters, required to hold the string and its terminating null character and the contents of buffer are undefined. If the function fails, the return value is zero. To get extended error information, call GetLastError.
      • GetCurrentProcessId

        int GetCurrentProcessId()
        This function returns the process identifier of the calling process.
        Returns:
        The return value is the process identifier of the calling process.
      • GetSystemTime

        void GetSystemTime​(GetSystemTimeFuncCall.SystemTime time)
        Retrieves the current system date and time in Coordinated Universal Time (UTC) format.
        Parameters:
        time - System time structure