public abstract class Kernel32Util extends java.lang.Object implements WinDef
WinDef.ATOM, WinDef.BOOL, WinDef.BOOLByReference, WinDef.BYTE, WinDef.CHAR, WinDef.CHARByReference, WinDef.DWORD, WinDef.DWORDByReference, WinDef.DWORDLONG, WinDef.HBITMAP, WinDef.HBRUSH, WinDef.HCURSOR, WinDef.HDC, WinDef.HFONT, WinDef.HGLRC, WinDef.HGLRCByReference, WinDef.HICON, WinDef.HINSTANCE, WinDef.HMENU, WinDef.HMODULE, WinDef.HPALETTE, WinDef.HPEN, WinDef.HRGN, WinDef.HRSRC, WinDef.HWND, WinDef.INT_PTR, WinDef.LCID, WinDef.LONG, WinDef.LONGByReference, WinDef.LONGLONG, WinDef.LONGLONGByReference, WinDef.LPARAM, WinDef.LPVOID, WinDef.LRESULT, WinDef.POINT, WinDef.PVOID, WinDef.RECT, WinDef.SCODE, WinDef.SCODEByReference, WinDef.SHORT, WinDef.UCHAR, WinDef.UINT, WinDef.UINT_PTR, WinDef.UINTByReference, WinDef.ULONG, WinDef.ULONGByReference, WinDef.ULONGLONG, WinDef.ULONGLONGByReference, WinDef.USHORT, WinDef.USHORTByReference, WinDef.WORD, WinDef.WORDByReference, WinDef.WPARAM
StdCallLibrary.StdCallCallback
Library.Handler
FUNCTION_MAPPER, STDCALL_CONVENTION
OPTION_ALLOW_OBJECTS, OPTION_CALLING_CONVENTION, OPTION_CLASSLOADER, OPTION_FUNCTION_MAPPER, OPTION_INVOCATION_MAPPER, OPTION_OPEN_FLAGS, OPTION_STRING_ENCODING, OPTION_STRUCTURE_ALIGNMENT, OPTION_TYPE_MAPPER
Constructor and Description |
---|
Kernel32Util() |
Modifier and Type | Method and Description |
---|---|
static void |
deleteFile(java.lang.String filename) |
static java.lang.String |
formatMessage(int code)
Format a message from the value obtained from
Kernel32.GetLastError() or Native.getLastError() . |
static java.lang.String |
formatMessage(WinNT.HRESULT code)
Format a message from an HRESULT.
|
static java.lang.String |
formatMessageFromHR(WinNT.HRESULT code)
Deprecated.
use
formatMessage(WinNT.HRESULT) instead. |
static java.lang.String |
formatMessageFromLastErrorCode(int code)
Format a system message from an error code.
|
static java.lang.String |
getComputerName()
Get current computer NetBIOS name.
|
static int |
getDriveType(java.lang.String rootName) |
static java.lang.String |
getEnvironmentVariable(java.lang.String name)
Get the value of an environment variable.
|
static int |
getFileAttributes(java.lang.String fileName)
Retrieves file system attributes for a specified file or directory.
|
static int |
getFileType(java.lang.String fileName)
Retrieves the result of GetFileType, provided the file exists.
|
static java.lang.String[] |
getLogicalDriveStrings()
Returns valid drives in the system.
|
static WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[] |
getLogicalProcessorInformation()
Convenience method to get the processor information.
|
static int |
getPrivateProfileInt(java.lang.String appName,
java.lang.String keyName,
int defaultValue,
java.lang.String fileName)
Retrieves an integer associated with a key in the specified section of an
initialization file.
|
static java.lang.String[] |
getPrivateProfileSection(java.lang.String appName,
java.lang.String fileName)
Retrieves all the keys and values for the specified section of an initialization file.
|
static java.lang.String[] |
getPrivateProfileSectionNames(java.lang.String fileName)
Retrieves the names of all sections in an initialization file.
|
static java.lang.String |
getPrivateProfileString(java.lang.String lpAppName,
java.lang.String lpKeyName,
java.lang.String lpDefault,
java.lang.String lpFileName)
Retrieves a string from the specified section in an initialization file.
|
static java.lang.String |
getTempPath()
Return the path designated for temporary files.
|
static void |
writePrivateProfileSection(java.lang.String appName,
java.lang.String[] strings,
java.lang.String fileName) |
static void |
writePrivateProfileString(java.lang.String appName,
java.lang.String keyName,
java.lang.String string,
java.lang.String fileName) |
public static java.lang.String getComputerName()
public static java.lang.String formatMessage(int code)
Kernel32.GetLastError()
or Native.getLastError()
.code
- intpublic static java.lang.String formatMessage(WinNT.HRESULT code)
code
- HRESULTpublic static java.lang.String formatMessageFromHR(WinNT.HRESULT code)
formatMessage(WinNT.HRESULT)
instead.public static java.lang.String formatMessageFromLastErrorCode(int code)
code
- Error code, typically a result of GetLastError.public static java.lang.String getTempPath()
public static void deleteFile(java.lang.String filename)
public static java.lang.String[] getLogicalDriveStrings()
public static int getFileAttributes(java.lang.String fileName)
fileName
- The name of the file or directory.public static int getFileType(java.lang.String fileName) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static int getDriveType(java.lang.String rootName)
public static java.lang.String getEnvironmentVariable(java.lang.String name)
name
- Name of the environment variable.public static final int getPrivateProfileInt(java.lang.String appName, java.lang.String keyName, int defaultValue, java.lang.String fileName)
appName
- The name of the section in the initialization file.keyName
- The name of the key whose value is to be retrieved. This value
is in the form of a string; the
Kernel32.GetPrivateProfileInt(java.lang.String, java.lang.String, int, java.lang.String)
function converts the
string into an integer and returns the integer.defaultValue
- The default value to return if the key name cannot be found in
the initialization file.fileName
- The name of the initialization file. If this parameter does
not contain a full path to the file, the system searches for
the file in the Windows directory.public static final java.lang.String getPrivateProfileString(java.lang.String lpAppName, java.lang.String lpKeyName, java.lang.String lpDefault, java.lang.String lpFileName)
lpAppName
- The name of the section containing the key name. If this
parameter is null
, the
Kernel32.GetPrivateProfileString(java.lang.String, java.lang.String, java.lang.String, char[], com.sun.jna.platform.win32.WinDef.DWORD, java.lang.String)
function copies all
section names in the file to the supplied buffer.lpKeyName
- The name of the key whose associated string is to be
retrieved. If this parameter is null
, all key names in
the section specified by the lpAppName
parameter are
returned.lpDefault
- A default string. If the lpKeyName
key cannot be found
in the initialization file,
Kernel32.GetPrivateProfileString(java.lang.String, java.lang.String, java.lang.String, char[], com.sun.jna.platform.win32.WinDef.DWORD, java.lang.String)
returns the default.
If this parameter is null
, the default is an empty
string, ""
.
Avoid specifying a default string with trailing blank
characters. The function inserts a null
character in
the lpReturnedString
buffer to strip any trailing
blanks.
lpFileName
- The name of the initialization file. If this parameter does
not contain a full path to the file, the system searches for
the file in the Windows directory.
If neither lpAppName
nor lpKeyName
is
null
and the destination buffer is too small to hold the
requested string, the string is truncated.
If either lpAppName
or lpKeyName
is null
and the destination buffer is too small to hold all the strings,
the last string is truncated and followed by two null
characters.
In the event the initialization file specified by
lpFileName
is not found, or contains invalid values, this
function will set errorno with a value of '0x2' (File Not Found).
To retrieve extended error information, call
Kernel32.GetLastError()
.
public static final void writePrivateProfileString(java.lang.String appName, java.lang.String keyName, java.lang.String string, java.lang.String fileName)
public static final WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[] getLogicalProcessorInformation()
public static final java.lang.String[] getPrivateProfileSection(java.lang.String appName, java.lang.String fileName)
Each string has the following format: key=string
.
This operation is atomic; no updates to the specified initialization file are allowed while this method is executed.
appName
- The name of the section in the initialization file.fileName
- The name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the
Windows directory.public static final java.lang.String[] getPrivateProfileSectionNames(java.lang.String fileName)
This operation is atomic; no updates to the initialization file are allowed while this method is executed.
fileName
- The name of the initialization file. If this parameter is NULL
, the function searches the Win.ini file. If this parameter does not
contain a full path to the file, the system searches for the file in the Windows directory.public static final void writePrivateProfileSection(java.lang.String appName, java.lang.String[] strings, java.lang.String fileName)
appName
- The name of the section in which data is written. This section name is typically the name of the calling application.strings
- The new key names and associated values that are to be written to the named section. Each entry must be of the form key=value
.fileName
- The name of the initialization file. If this parameter does not contain a full path for the file, the function searches the Windows directory
for the file. If the file does not exist and lpFileName does not contain a full path, the function creates the file in the Windows directory.