com.sun.jna.platform.win32.W32Errors Java Examples

The following examples show how to use com.sun.jna.platform.win32.W32Errors. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsumeWindowsEventLogTest.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public static List<WinNT.HANDLE> mockEventHandles(WEvtApi wEvtApi, Kernel32 kernel32, List<String> eventXmls) {
    List<WinNT.HANDLE> eventHandles = new ArrayList<>();
    for (String eventXml : eventXmls) {
        WinNT.HANDLE eventHandle = mock(WinNT.HANDLE.class);
        when(wEvtApi.EvtRender(isNull(WinNT.HANDLE.class), eq(eventHandle), eq(WEvtApi.EvtRenderFlags.EVENT_XML),
                anyInt(), any(Pointer.class), any(Pointer.class), any(Pointer.class))).thenAnswer(invocation -> {
            Object[] arguments = invocation.getArguments();
            Pointer bufferUsed = (Pointer) arguments[5];
            byte[] array = Charsets.UTF_16LE.encode(eventXml).array();
            if (array.length > (int) arguments[3]) {
                when(kernel32.GetLastError()).thenReturn(W32Errors.ERROR_INSUFFICIENT_BUFFER).thenReturn(W32Errors.ERROR_SUCCESS);
            } else {
                ((Pointer) arguments[4]).write(0, array, 0, array.length);
            }
            bufferUsed.setInt(0, array.length);
            return false;
        });
        eventHandles.add(eventHandle);
    }
    return eventHandles;
}
 
Example #2
Source File: ConsumeWindowsEventLogTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static List<WinNT.HANDLE> mockEventHandles(WEvtApi wEvtApi, Kernel32 kernel32, List<String> eventXmls) {
    List<WinNT.HANDLE> eventHandles = new ArrayList<>();
    for (String eventXml : eventXmls) {
        WinNT.HANDLE eventHandle = mock(WinNT.HANDLE.class);
        when(wEvtApi.EvtRender(isNull(), eq(eventHandle), eq(WEvtApi.EvtRenderFlags.EVENT_XML),
                anyInt(), any(Pointer.class), any(Pointer.class), any(Pointer.class))).thenAnswer(invocation -> {
            Object[] arguments = invocation.getArguments();
            Pointer bufferUsed = (Pointer) arguments[5];
            byte[] array = StandardCharsets.UTF_16LE.encode(eventXml).array();
            if (array.length > (int) arguments[3]) {
                when(kernel32.GetLastError()).thenReturn(W32Errors.ERROR_INSUFFICIENT_BUFFER).thenReturn(W32Errors.ERROR_SUCCESS);
            } else {
                ((Pointer) arguments[4]).write(0, array, 0, array.length);
            }
            bufferUsed.setInt(0, array.length);
            return false;
        });
        eventHandles.add(eventHandle);
    }
    return eventHandles;
}
 
Example #3
Source File: DwmApi.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return 0 - color in format 0xAARRGGBB, 1 - opaque
 */
public static int[] DwmGetColorizationColor() {
  IntByReference colorRef = new IntByReference();
  IntByReference opaqueRef = new IntByReference();
  WinNT.HRESULT hresult = DwmApi.INSTANCE.DwmGetColorizationColor(colorRef, opaqueRef);
  if(W32Errors.S_OK.equals(hresult)) {
    return new int[] {colorRef.getValue(), opaqueRef.getValue()};
  }
  return new int[2];
}
 
Example #4
Source File: DwmApi.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean DwmIsCompositionEnabled() {
  IntByReference reference = new IntByReference();
  WinNT.HRESULT hresult = INSTANCE.DwmIsCompositionEnabled(reference);
  return W32Errors.S_OK.equals(hresult) && reference.getValue() == 1;
}