本文整理匯總了Java中com.sun.jna.Native.getNativeSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Native.getNativeSize方法的具體用法?Java Native.getNativeSize怎麽用?Java Native.getNativeSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.jna.Native
的用法示例。
在下文中一共展示了Native.getNativeSize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDiskSize
import com.sun.jna.Native; //導入方法依賴的package包/類
private long getDiskSize(Disk disk) {
long result = -1l;
Kernel32 kernel32 = Kernel32.INSTANCE;
HANDLE diskHandle = kernel32.CreateFile(disk.path, WinNT.GENERIC_READ, WinNT.FILE_SHARE_READ, null,
WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
if (WinBase.INVALID_HANDLE_VALUE.equals(diskHandle)) {
return result;
}
try {
Memory output = new Memory(Native.getNativeSize(LARGE_INTEGER.class));
IntByReference lpBytes = new IntByReference();
boolean success = kernel32.DeviceIoControl(diskHandle,
WinioctlUtil.CTL_CODE(Winioctl.FILE_DEVICE_DISK, 0x17, Winioctl.METHOD_BUFFERED,
Winioctl.FILE_READ_ACCESS),
null, 0, output, Native.getNativeSize(LARGE_INTEGER.class), lpBytes, null);
// TODO: Check success?
result = output.getLong(0);
}
finally {
Kernel32Util.closeHandle(diskHandle);
}
return result;
}
示例2: getIntSize
import com.sun.jna.Native; //導入方法依賴的package包/類
/**
* Gets the size of an integer in bytes on the current platform.
*
* @return The size of an integer in bytes
*/
public static int getIntSize() {
if (intSize == -1) {
intSize = Native.getNativeSize(int.class);
}
return intSize;
}