当前位置: 首页>>代码示例>>Java>>正文


Java WinNT类代码示例

本文整理汇总了Java中com.sun.jna.platform.win32.WinNT的典型用法代码示例。如果您正苦于以下问题:Java WinNT类的具体用法?Java WinNT怎么用?Java WinNT使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WinNT类属于com.sun.jna.platform.win32包,在下文中一共展示了WinNT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDiskSize

import com.sun.jna.platform.win32.WinNT; //导入依赖的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;
}
 
开发者ID:ciphertechsolutions,项目名称:IO,代码行数:24,代码来源:DeviceManager.java

示例2: getWindowsProcessId

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * @param process NiFi Registry Process Reference
 * @param logger  Logger Reference for Debug
 * @return        Returns pid or null in-case pid could not be determined
 * This method takes {@link Process} and {@link Logger} and returns
 * the platform specific Handle for Win32 Systems, a.k.a <b>pid</b>
 * In-case it fails to determine the pid, it will return Null.
 * Purpose for the Logger is to log any interaction for debugging.
 */
private static Long getWindowsProcessId(final Process process, final Logger logger) {
    /* determine the pid on windows plattforms */
    try {
        Field f = process.getClass().getDeclaredField("handle");
        f.setAccessible(true);
        long handl = f.getLong(process);

        Kernel32 kernel = Kernel32.INSTANCE;
        WinNT.HANDLE handle = new WinNT.HANDLE();
        handle.setPointer(Pointer.createConstant(handl));
        int ret = kernel.GetProcessId(handle);
        logger.debug("Detected pid: {}", ret);
        return Long.valueOf(ret);
    } catch (final IllegalAccessException | NoSuchFieldException nsfe) {
        logger.debug("Could not find PID for child process due to {}", nsfe);
    }
    return null;
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:28,代码来源:OSUtils.java

示例3: while

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Finds the given process in the process list.
 *
 * @param processEntry The process entry.
 * @param filenamePattern pattern matching the filename of the process.
 * @return The found process entry.
 */
public static boolean findProcessEntry
                (final Tlhelp32.PROCESSENTRY32.ByReference processEntry,
                 final Pattern filenamePattern) {
    Kernel32 kernel32 = Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS);

    WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0));

    boolean found = false;

    try {
        while (kernel32.Process32Next(snapshot, processEntry)) {
            String fname = Native.toString(processEntry.szExeFile);

            if (fname != null && filenamePattern.matcher(fname).matches()) {
                found = true;
                break;
            }
        }
    } finally {
        kernel32.CloseHandle(snapshot);
    }

    return found;
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:32,代码来源:Utils.java

示例4: getPattern

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Gets the pattern
 * @return The pattern
 * @throws AutomationException Something went wrong getting the pattern
 */
private IUIAutomationInvokePattern getPattern() throws AutomationException {
    if (this.rawPattern != null) {
        return this.rawPattern;
    } else {
        PointerByReference pbr = new PointerByReference();

        WinNT.HRESULT result0 = this.getRawPatternPointer(pbr);

        if (COMUtils.SUCCEEDED(result0)) {
            return this.convertPointerToInterface(pbr);
        } else {
            throw new AutomationException(result0.intValue());
        }
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:21,代码来源:Invoke.java

示例5: getPattern

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Gets the pointer
 * @return Underlying pointer
 * @throws AutomationException Automation has gone wrong
 */
private IUIAutomationSelectionPattern getPattern() throws AutomationException {
    if (this.rawPattern != null) {
        return this.rawPattern;
    } else {
        PointerByReference pbr = new PointerByReference();

        WinNT.HRESULT result0 = this.getRawPatternPointer(pbr);

        if (COMUtils.SUCCEEDED(result0)) {
            return this.convertPointerToInterface(pbr);
        } else {
            throw new AutomationException(result0.intValue());
        }
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:21,代码来源:Selection.java

示例6: getPattern

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Gets the pattern interface.
 *
 * @return The toggle pattern interface
 * @throws AutomationException Something went wrong with the automation library.
 */
private IUIAutomationTogglePattern getPattern() throws AutomationException {
    if (this.rawPattern != null) {
        return this.rawPattern;
    } else {
        PointerByReference pbr = new PointerByReference();

        WinNT.HRESULT result0 = this.getRawPatternPointer(pbr);

        if (COMUtils.SUCCEEDED(result0)) {
            return this.convertPointerToInterface(pbr);
        } else {
            throw new AutomationException(result0.intValue());
        }
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:22,代码来源:Toggle.java

示例7: getPattern

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Gets the pattern.
 * @return The pattern
 * @throws AutomationException Something went wrong getting the pattern
 */
private IUIAutomationExpandCollapsePattern getPattern()
        throws AutomationException {
    if (this.rawPattern != null) {
        return this.rawPattern;
    } else {
        PointerByReference pbr = new PointerByReference();

        WinNT.HRESULT result0 = this.getRawPatternPointer(pbr);

        if (COMUtils.SUCCEEDED(result0)) {
            return this.convertPointerToInterface(pbr);
        } else {
            throw new AutomationException(result0.intValue());
        }
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:22,代码来源:ExpandCollapse.java

示例8: getSelectionContainer

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Gets the selection container
 * @return The selection container
 * @throws AutomationException Something has gone wrong in automation
 */
public AutomationElement getSelectionContainer() throws AutomationException {
    PointerByReference pbr = new PointerByReference();

    final int res = this.getPattern().getCurrentSelectionContainer(pbr);
    if (res != 0) {
        throw new AutomationException(res);
    }

    Unknown unkConditionA = makeUnknown(pbr.getValue());
    PointerByReference pUnknownA = new PointerByReference();

    WinNT.HRESULT resultA = unkConditionA.QueryInterface(new Guid.REFIID(IUIAutomationElement.IID), pUnknownA);
    if (COMUtils.SUCCEEDED(resultA)) {
        return new AutomationElement(convertPointerToElementInterface(pUnknownA));
    } else {
        throw new AutomationException(resultA.intValue());
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:24,代码来源:SelectionItem.java

示例9: getItem

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Gets the element associated with the grid cell
 * @param x X position
 * @param y Y position
 * @return The Element from the grid
 * @throws AutomationException Something amiss with automation
 */
public AutomationElement getItem(int x, int y) throws AutomationException {
    PointerByReference cell = this.getRawItem(x, y);

    Unknown uRoot = makeUnknown(cell.getValue());

    PointerByReference pbr = new PointerByReference();

    WinNT.HRESULT result0 = uRoot.QueryInterface(new Guid.REFIID(IUIAutomationElement.IID), pbr);

    if (COMUtils.SUCCEEDED(result0)) {
        return new AutomationElement(convertPointerToElementInterface(pbr));
    } else {
        throw new AutomationException(result0.intValue());
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:23,代码来源:Grid.java

示例10: if

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Gets the handle of a process from the process entry.
 *
 * @param processEntry The processEntry to use
 * @return The handle
 * @throws AutomationException Thrown if the handle cannot be determined
 */
public static WinNT.HANDLE getHandleFromProcessEntry
                (final Tlhelp32.PROCESSENTRY32.ByReference processEntry)
        throws AutomationException {
	ensureWinApiInstances();
	
    WinNT.HANDLE handle = kernel32.OpenProcess (
            0x0400 |    /* PROCESS_QUERY_INFORMATION */
            0x0800 |    /* PROCESS_SUSPEND_RESUME */
            0x0001 |    /* PROCESS_TERMINATE */
            0x00100000  /* SYNCHRONIZE */,
            false,
            processEntry.th32ProcessID.intValue());

    if (handle == null) {
        throw new AutomationException("OpenProcess failed");
    }

    return handle;
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:27,代码来源:Utils.java

示例11: createWrapper

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Creates the wrapper.
 */
private void createWrapper() {
    CANALIZED_OLE32_INSTANCE = Canalizer.canalize(com.sun.jna.platform.win32.Ole32.INSTANCE);

    CANALIZED_OLE32_INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_APARTMENTTHREADED);

    PointerByReference pbr = new PointerByReference();

    WinNT.HRESULT hr = CANALIZED_OLE32_INSTANCE.CoCreateInstance(
            IUIAutomation.CLSID,
            null,
            WTypes.CLSCTX_SERVER,
            IUIAutomation.IID,
            pbr);

    COMUtils.checkRC(hr);

    unknown = new Unknown(pbr.getValue());
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:22,代码来源:Ole32Wrapper.java

示例12: getExpandCollapsePatternFromItem

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
/**
 * Gets the raw pattern from the given element.
 * @param item The Element
 * @return The raw collapse pattern
 * @throws AutomationException Failed to get pattern
 */
public IUIAutomationExpandCollapsePattern getExpandCollapsePatternFromItem(AutomationElement item)
                    throws AutomationException {
    PointerByReference pElement = item.getPattern(PatternID.ExpandCollapse.getValue());

    Unknown unkConditionA = makeUnknown(pElement.getValue());

    PointerByReference pUnknownA = new PointerByReference();

    WinNT.HRESULT resultA = unkConditionA.QueryInterface(new Guid.REFIID(IUIAutomationExpandCollapsePattern.IID), pUnknownA);
    if (COMUtils.SUCCEEDED(resultA)) {
        return IUIAutomationExpandCollapsePatternConverter.PointerToInterface(pUnknownA);
    } else {
        throw new AutomationException("QueryInterface failed");
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:22,代码来源:AutomationMainMenu.java

示例13: test_getItem_Throws_Exception_When_Pattern_Returns_Error_From_GetItem

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
@Test
@Ignore("Need to build up the mocking")
public void test_getItem_Throws_Exception_When_Pattern_Returns_Error_From_GetItem() throws Exception {
    Grid pattern = new Grid(rawPattern);

    Grid spyPattern = Mockito.spy(pattern);

    doAnswer(invocation -> new WinNT.HRESULT(0)).when(mockUnknown).QueryInterface(any(Guid.REFIID.class), any(PointerByReference.class));

    IUIAutomationGridPattern mockGrid = Mockito.mock(IUIAutomationGridPattern.class);

    doReturn(mockUnknown)
            .when(spyPattern)
            .makeUnknown(any());

    AutomationElement element = spyPattern.getItem(0,0);
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:18,代码来源:GridPatternTest.java

示例14: testCreateFalseCondtion

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
@Test
public void testCreateFalseCondtion() {
    UIAutomation instance = UIAutomation.getInstance();

    try {
        PointerByReference condition = instance.createFalseCondition();

        Unknown unk = new Unknown(condition.getValue());

        PointerByReference pUnknown1 = new PointerByReference();

        WinNT.HRESULT result = unk.QueryInterface(new Guid.REFIID(IUIAutomationCondition.IID), pUnknown1);

        assertTrue("Create FalseCondition:" + COMUtils.SUCCEEDED(result), COMUtils.SUCCEEDED(result));
    } catch (AutomationException ex) {
        assertTrue("Ouch", false);
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:19,代码来源:UIAutomationTest.java

示例15: testCreatePropertyCondition

import com.sun.jna.platform.win32.WinNT; //导入依赖的package包/类
@Test
public void testCreatePropertyCondition() {
    UIAutomation instance = UIAutomation.getInstance();

    Variant.VARIANT.ByValue variant = new Variant.VARIANT.ByValue();
    WTypes.BSTR sysAllocated = OleAuto.INSTANCE.SysAllocString("SOMETHING");
    variant.setValue(Variant.VT_BSTR, sysAllocated);

    try {
        try {
            PointerByReference pCondition = instance.createPropertyCondition(PropertyID.AutomationId.getValue(), variant);

            Unknown unk = new Unknown(pCondition.getValue());

            PointerByReference pUnknown1 = new PointerByReference();

            WinNT.HRESULT result = unk.QueryInterface(new Guid.REFIID(IUIAutomationCondition.IID), pUnknown1);

            assertTrue("CreatePropertyCondition:" + COMUtils.SUCCEEDED(result), COMUtils.SUCCEEDED(result));
        } catch (AutomationException ex) {
            assertTrue("Exception", false);
        }
    } finally {
        OleAuto.INSTANCE.SysFreeString(sysAllocated);
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:27,代码来源:UIAutomationTest.java


注:本文中的com.sun.jna.platform.win32.WinNT类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。