JNA API 4.0.0

com.sun.jna.platform.win32
Class Kernel32Util

java.lang.Object
  extended by com.sun.jna.platform.win32.Kernel32Util
All Implemented Interfaces:
AltCallingConvention, Library, WinDef, StdCall, StdCallLibrary

public abstract class Kernel32Util
extends Object
implements WinDef

Kernel32 utility API.

Author:
dblock[at]dblock.org, markus[at]headcrashing[dot]eu

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.sun.jna.platform.win32.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.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
 
Nested classes/interfaces inherited from interface com.sun.jna.win32.StdCallLibrary
StdCallLibrary.StdCallCallback
 
Nested classes/interfaces inherited from interface com.sun.jna.Library
Library.Handler
 
Field Summary
 
Fields inherited from interface com.sun.jna.platform.win32.WinDef
MAX_PATH
 
Fields inherited from interface com.sun.jna.win32.StdCallLibrary
FUNCTION_MAPPER, STDCALL_CONVENTION
 
Fields inherited from interface com.sun.jna.Library
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 Summary
Kernel32Util()
           
 
Method Summary
static void deleteFile(String filename)
           
static String formatMessage(int code)
          Format a message from the value obtained from Kernel32.GetLastError() or Native.getLastError().
static String formatMessage(WinNT.HRESULT code)
          Format a message from an HRESULT.
static String formatMessageFromHR(WinNT.HRESULT code)
          Deprecated. use formatMessage(WinNT.HRESULT) instead.
static String formatMessageFromLastErrorCode(int code)
          Format a system message from an error code.
static String getComputerName()
          Get current computer NetBIOS name.
static int getDriveType(String rootName)
           
static String getEnvironmentVariable(String name)
          Get the value of an environment variable.
static int getFileAttributes(String fileName)
          Retrieves file system attributes for a specified file or directory.
static int getFileType(String fileName)
          Retrieves the result of GetFileType, provided the file exists.
static 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(String appName, String keyName, int defaultValue, String fileName)
          Retrieves an integer associated with a key in the specified section of an initialization file.
static String getPrivateProfileString(String lpAppName, String lpKeyName, String lpDefault, String lpFileName)
          Retrieves a string from the specified section in an initialization file.
static String getTempPath()
          Return the path designated for temporary files.
static void writePrivateProfileString(String appName, String keyName, String string, String fileName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Kernel32Util

public Kernel32Util()
Method Detail

getComputerName

public static String getComputerName()
Get current computer NetBIOS name.

Returns:
Netbios name.

formatMessage

public static String formatMessage(int code)
Format a message from the value obtained from Kernel32.GetLastError() or Native.getLastError().

Parameters:
code - int
Returns:
Formatted message.

formatMessage

public static String formatMessage(WinNT.HRESULT code)
Format a message from an HRESULT.

Parameters:
code - HRESULT
Returns:
Formatted message.

formatMessageFromHR

public static String formatMessageFromHR(WinNT.HRESULT code)
Deprecated. use formatMessage(WinNT.HRESULT) instead.


formatMessageFromLastErrorCode

public static String formatMessageFromLastErrorCode(int code)
Format a system message from an error code.

Parameters:
code - Error code, typically a result of GetLastError.
Returns:
Formatted message.

getTempPath

public static String getTempPath()
Return the path designated for temporary files.

Returns:
Path.

deleteFile

public static void deleteFile(String filename)

getLogicalDriveStrings

public static String[] getLogicalDriveStrings()
Returns valid drives in the system.

Returns:
An array of valid drives.

getFileAttributes

public static int getFileAttributes(String fileName)
Retrieves file system attributes for a specified file or directory.

Parameters:
fileName - The name of the file or directory.
Returns:
The attributes of the specified file or directory.

getFileType

public static int getFileType(String fileName)
                       throws FileNotFoundException
Retrieves the result of GetFileType, provided the file exists.

Throws:
FileNotFoundException

getDriveType

public static int getDriveType(String rootName)
Returns:
One of the WinBase.DRIVE_* constants.

getEnvironmentVariable

public static String getEnvironmentVariable(String name)
Get the value of an environment variable.

Parameters:
name - Name of the environment variable.
Returns:
Value of an environment variable.

getPrivateProfileInt

public static final int getPrivateProfileInt(String appName,
                                             String keyName,
                                             int defaultValue,
                                             String fileName)
Retrieves an integer associated with a key in the specified section of an initialization file.

Parameters:
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.
Returns:
The retrieved integer, or the default if not found.

getPrivateProfileString

public static final String getPrivateProfileString(String lpAppName,
                                                   String lpKeyName,
                                                   String lpDefault,
                                                   String lpFileName)
Retrieves a string from the specified section in an initialization file.

Parameters:
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.
Returns:

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().


writePrivateProfileString

public static final void writePrivateProfileString(String appName,
                                                   String keyName,
                                                   String string,
                                                   String fileName)

getLogicalProcessorInformation

public static final WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[] getLogicalProcessorInformation()
Convenience method to get the processor information. Takes care of auto-growing the array.

Returns:
the array of processor information.

JNA API 4.0.0

Copyright © 2007-2013 Timothy Wall. All Rights Reserved.