本文整理汇总了Java中com.sun.jna.platform.win32.WinBase类的典型用法代码示例。如果您正苦于以下问题:Java WinBase类的具体用法?Java WinBase怎么用?Java WinBase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WinBase类属于com.sun.jna.platform.win32包,在下文中一共展示了WinBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDiskSize
import com.sun.jna.platform.win32.WinBase; //导入依赖的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: calc
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
private void calc()
{
if (System.currentTimeMillis() - _lastCall < 500)
return;
WinBase.MEMORYSTATUSEX lpBuffer = new WinBase.MEMORYSTATUSEX();
lpBuffer.dwLength = new DWORD(lpBuffer.size());
if (Kernel32.INSTANCE.GlobalMemoryStatusEx(lpBuffer))
{
lpBuffer.read();
_freeRAM = lpBuffer.ullAvailPhys.longValue();
_totalRAM = lpBuffer.ullTotalPhys.longValue();
_lastCall = System.currentTimeMillis();
}
else
{
if (_logger != null)
_logger.severe("ERROR: could not read free/total RAM");
else
System.out.println("ERROR: could not read free/total RAM");
}
}
示例3: processMessage
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
private LRESULT processMessage(HWND hwnd, WPARAM wParam, LPARAM lParam) {
WinBase.SECURITY_ATTRIBUTES psa = null;
String mapname = readFileNameFromInput(lParam);
sharedFile
= libK.CreateFileMapping(WinBase.INVALID_HANDLE_VALUE,
psa,
WinNT.PAGE_READWRITE,
0,
8192, // AGENT_MAX_MSGLEN
mapname);
sharedMemory
= Kernel32.INSTANCE.MapViewOfFile(sharedFile,
WinNT.SECTION_MAP_WRITE,
0, 0, 0);
int ret = answerIfDevicePresent(sharedMemory);
disconnectFromSharedMemory();
return new LRESULT(ret);
}
示例4: terminate
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
public boolean terminate() {
Kernel32.HANDLE process = Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_TERMINATE | WinNT.SYNCHRONIZE, false, pid);
if (process.getPointer() == null) {
Runner.logger.warn("Unable to find process " + name + "(" + pid + ")");
return false;
} else {
Kernel32.INSTANCE.TerminateProcess(process, 1);
int wait = Kernel32.INSTANCE.WaitForSingleObject(process, 1000);
if (wait != WinBase.WAIT_OBJECT_0) {
Runner.logger.warn("Timed out while waiting for process " + name + "(" + pid + ") to end");
return false;
}
Kernel32.INSTANCE.CloseHandle(process);
return true;
}
}
示例5: _truncateFile
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
@Override
protected void _truncateFile(long size) throws IOException {
// TODO Handle lp of size
int resSFP = MMFKernel32.INSTANCE.SetFilePointer(file, size, Pointer.NULL, 1);
if (WinBase.INVALID_SET_FILE_POINTER == resSFP) {
throw new IOException("INVALID_SET_FILE_POINTER: " + Kernel32.INSTANCE.GetLastError());
}
Kernel32.INSTANCE.CloseHandle(mapping);
mapping = null;
boolean resSEOF = MMFKernel32.INSTANCE.SetEndOfFile(file);
if (!resSEOF) {
throw new IOException(
"Unable to SetEndOfFile: " + getLastErrorAsString());
}
}
示例6: getPageRanges
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
public static List<MEMORY_BASIC_INFORMATION> getPageRanges(WinNT.HANDLE hOtherProcess) {
List<MEMORY_BASIC_INFORMATION> ret = new ArrayList<>();
MEMORY_BASIC_INFORMATION mbi;
WinBase.SYSTEM_INFO si = new WinBase.SYSTEM_INFO();
Kernel32.INSTANCE.GetSystemInfo(si);
Pointer lpMem = si.lpMinimumApplicationAddress;
while (pointerToAddress(lpMem) < pointerToAddress(si.lpMaximumApplicationAddress)) {
mbi = new MEMORY_BASIC_INFORMATION();
BaseTSD.SIZE_T t = Kernel32.INSTANCE.VirtualQueryEx(hOtherProcess, lpMem, mbi, new BaseTSD.SIZE_T(mbi.size()));
if (t.longValue() == 0) {
Logger.getLogger(Win32ProcessTools.class.getName()).log(Level.SEVERE, "Cannot get page ranges. Last error:" + Kernel32.INSTANCE.GetLastError());
break;
}
ret.add(mbi);
lpMem = new Pointer(pointerToAddress(mbi.baseAddress) + mbi.regionSize.longValue());
}
return ret;
}
示例7: CygwinPtyProcess
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
public CygwinPtyProcess(String[] command, Map<String, String> environment, String workingDirectory, File logFile, boolean console)
throws IOException {
String pipePrefix = String.format("\\\\.\\pipe\\cygwinpty-%d-%d-", KERNEL32.GetCurrentProcessId(), processCounter.getAndIncrement());
String inPipeName = pipePrefix + "in";
String outPipeName = pipePrefix + "out";
String errPipeName = pipePrefix + "err";
myInputHandle = KERNEL32.CreateNamedPipeA(inPipeName, PIPE_ACCESS_OUTBOUND | WinNT.FILE_FLAG_OVERLAPPED, 0, 1, 0, 0, 0, null);
myOutputHandle = KERNEL32.CreateNamedPipeA(outPipeName, PIPE_ACCESS_INBOUND | WinNT.FILE_FLAG_OVERLAPPED, 0, 1, 0, 0, 0, null);
myErrorHandle =
console ? KERNEL32.CreateNamedPipeA(errPipeName, PIPE_ACCESS_INBOUND | WinNT.FILE_FLAG_OVERLAPPED, 0, 1, 0, 0, 0, null) : null;
if (myInputHandle == WinBase.INVALID_HANDLE_VALUE ||
myOutputHandle == WinBase.INVALID_HANDLE_VALUE ||
myErrorHandle == WinBase.INVALID_HANDLE_VALUE) {
closeHandles();
throw new IOException("Unable to create a named pipe");
}
myInputPipe = new NamedPipe(myInputHandle, false);
myOutputPipe = new NamedPipe(myOutputHandle, false);
myErrorPipe = myErrorHandle != null ? new NamedPipe(myErrorHandle, false) : null;
myProcess = startProcess(inPipeName, outPipeName, errPipeName, workingDirectory, command, environment, logFile, console);
}
示例8: getSubKeys
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
/**
* Get all sub keys of a key.
*
* @param rootKey
* root key
* @param parent
* key name
* @return array with all sub key names
*/
public static String[] getSubKeys(REGISTRY_ROOT_KEY rootKey, String parent)
{
Advapi32 advapi32;
HKEY handle = null;
int dwIndex;
char[] lpName;
IntByReference lpcName;
WinBase.FILETIME lpftLastWriteTime;
TreeSet<String> subKeys = new TreeSet<String>();
advapi32 = Advapi32.INSTANCE;
handle = openKey(rootKey, parent, WinNT.KEY_READ);
lpName = new char[256];
lpcName = new IntByReference(256);
lpftLastWriteTime = new WinNT.FILETIME();
if (handle != null)
{
dwIndex = 0;
while (advapi32.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null, null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS)
{
subKeys.add(new String(lpName, 0, lpcName.getValue()));
lpcName.setValue(256);
dwIndex++;
}
advapi32.RegCloseKey(handle);
}
return (subKeys.toArray(new String[]
{}));
}
示例9: getErrorString
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
private static String getErrorString(int errorcode) {
// Thanks to [email protected]://stackoverflow.com/a/455533/2060704
PointerByReference str = new PointerByReference();
int ret = Kernel32.INSTANCE.FormatMessage(
WinBase.FORMAT_MESSAGE_FROM_SYSTEM | WinBase.FORMAT_MESSAGE_ALLOCATE_BUFFER | WinBase.FORMAT_MESSAGE_IGNORE_INSERTS,
Pointer.NULL,
errorcode,
// Can't use other locales for some reason sometimes. Rust does seem to have the same problem
// https://github.com/rust-lang/rust/commit/5e8e1b515a9ef1cd38ee0c71f032415906a7f42d
// using system default for now
0x0800 /* system default */, // https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693%28v=vs.85%29.aspx
str,
0,
Pointer.NULL);
if (ret == 0) {
// ret == 15100 when locale was not found.
// show the code at least in any case
return "(FormatMessage returned with " + Kernel32.INSTANCE.GetLastError() + ", no error string could be fetched)";
}
if (str.getPointer() != Pointer.NULL) {
// Might be extremely wrong for older, unsupported systems according to
// http://bytes.com/topic/c/answers/680878-sizeof-tchar
// or http://wiki.mcneel.com/developer/sdksamples/countof
// TCHAR is either char (1 byte) or wchar_t (2 byte); using wchar_t for now
String string = str.getValue().getWideString(0);
Kernel32.INSTANCE.LocalFree(str.getValue());
return string;
} else {
throw new RuntimeException("Unable to obtain errorstring for errorcode " + errorcode);
}
}
示例10: GPS
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
public GPS(CefBrowser pBrowser, Option pOptions)
{
this.sharedFile = Kernel32.INSTANCE.CreateFileMapping(
WinBase.INVALID_HANDLE_VALUE, null, WinNT.PAGE_EXECUTE_READWRITE, 0, MEM_MAP_SIZE, MEM_MAP_NAME);
this.sharedMemory = Kernel32.INSTANCE.MapViewOfFile(
this.sharedFile, WinNT.SECTION_MAP_READ, 0, 0, MEM_MAP_SIZE);
this.TheBrowser = pBrowser;
this.TheOptions = pOptions;
}
示例11: openDevice
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
public static boolean openDevice() throws IOException {
/* Kernel32RW.GENERIC_READ | Kernel32RW.GENERIC_WRITE not used in dwDesiredAccess field for system devices such a keyboard or mouse */
int shareMode = WinNT.FILE_SHARE_READ | WinNT.FILE_SHARE_WRITE;
int Access = WinNT.GENERIC_WRITE | WinNT.GENERIC_READ;
HandleToDevice = Kernel32.INSTANCE.CreateFile(
Devices.getConnectedDeviceWin32().getDevPath(),
Access,
shareMode,
null,
WinNT.OPEN_EXISTING,
0,//WinNT.FILE_FLAG_OVERLAPPED,
(WinNT.HANDLE)null);
if (HandleToDevice == WinBase.INVALID_HANDLE_VALUE) throw new IOException(getLastError());
return true;
}
示例12: openDeviceAsync
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
public static boolean openDeviceAsync() throws IOException {
/* Kernel32RW.GENERIC_READ | Kernel32RW.GENERIC_WRITE not used in dwDesiredAccess field for system devices such a keyboard or mouse */
int shareMode = WinNT.FILE_SHARE_READ | WinNT.FILE_SHARE_WRITE;
int Access = WinNT.GENERIC_WRITE | WinNT.GENERIC_READ;
HandleToDevice = Kernel32.INSTANCE.CreateFile(
Devices.getConnectedDeviceWin32().getDevPath(),
Access,
shareMode,
null,
WinNT.OPEN_EXISTING,
WinNT.FILE_FLAG_OVERLAPPED,
(WinNT.HANDLE)null);
if (HandleToDevice == WinBase.INVALID_HANDLE_VALUE) throw new IOException(getLastError());
return true;
}
示例13: createEvent
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
public static WinNT.HANDLE createEvent() throws IOException {
WinNT.HANDLE hevent = kernel32.CreateEvent(null, false, false, null);
int res = kernel32.GetLastError();
if (hevent == WinBase.INVALID_HANDLE_VALUE || res!=0)
throw new IOException(JKernel32.getLastError());
return hevent;
}
示例14: closeDevice
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
public static boolean closeDevice() {
boolean result = true;
if (HandleToDevice != WinBase.INVALID_HANDLE_VALUE) {
result = kernel32.CloseHandle(HandleToDevice);
}
HandleToDevice = WinBase.INVALID_HANDLE_VALUE;
return result;
}
示例15: CreateFile
import com.sun.jna.platform.win32.WinBase; //导入依赖的package包/类
WinNT.HANDLE CreateFile(
String lpFileName,
int dwDesiredAccess,
int dwShareMode,
WinBase.SECURITY_ATTRIBUTES lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
WinNT.HANDLE hTemplateFile);