Package com.sun.jna.platform.win32.WinNT

Examples of com.sun.jna.platform.win32.WinNT.HANDLEByReference


      assertEquals(WinNT.SE_BACKUP_NAME.length(), cchName.getValue());
      assertEquals(WinNT.SE_BACKUP_NAME, Native.toString(lpName));
    }
   
    public void testAdjustTokenPrivileges() {
      HANDLEByReference hToken = new HANDLEByReference();
      assertTrue(Advapi32.INSTANCE.OpenProcessToken(Kernel32.INSTANCE.GetCurrentProcess(),
          WinNT.TOKEN_ADJUST_PRIVILEGES | WinNT.TOKEN_QUERY, hToken));
     
      // Find an already enabled privilege
      TOKEN_PRIVILEGES tp = new TOKEN_PRIVILEGES(1024);
      IntByReference returnLength = new IntByReference();
      assertTrue(Advapi32.INSTANCE.GetTokenInformation(hToken.getValue(),  WinNT.TOKEN_INFORMATION_CLASS.TokenPrivileges,
          tp, tp.size(), returnLength));
      assertTrue(tp.PrivilegeCount.intValue() > 0);
     
      WinNT.LUID luid = null;
      for (int i=0; i<tp.PrivilegeCount.intValue(); i++) {
        if ((tp.Privileges[i].Attributes.intValue() & WinNT.SE_PRIVILEGE_ENABLED) > 0) {
          luid = tp.Privileges[i].Luid;
        }
      }
      assertTrue(luid != null);     
     
      // Re-enable it. That should succeed.
      tp = new WinNT.TOKEN_PRIVILEGES(1);
      tp.Privileges[0] = new WinNT.LUID_AND_ATTRIBUTES(luid, new DWORD(WinNT.SE_PRIVILEGE_ENABLED));
     
      assertTrue(Advapi32.INSTANCE.AdjustTokenPrivileges(hToken.getValue(), false, tp, 0, null, null));
      assertTrue(Kernel32.INSTANCE.CloseHandle(hToken.getValue()));
    }
View Full Code Here


      assertTrue(Kernel32.INSTANCE.SetHandleInformation(hFile, WinBase.HANDLE_FLAG_PROTECT_FROM_CLOSE, 0));
      assertTrue(Kernel32.INSTANCE.CloseHandle(hFile));
    }
   
    public void testCreatePipe() {
      HANDLEByReference hReadPipe = new HANDLEByReference();
      HANDLEByReference hWritePipe = new HANDLEByReference();
     
      assertTrue(Kernel32.INSTANCE.CreatePipe(hReadPipe, hWritePipe, null, 0));
      assertTrue(Kernel32.INSTANCE.CloseHandle(hReadPipe.getValue()));
      assertTrue(Kernel32.INSTANCE.CloseHandle(hWritePipe.getValue()));
    }
View Full Code Here

              ptsServerExpiry);
          assertTrue(serverRc == W32Errors.SEC_I_CONTINUE_NEEDED || serverRc == W32Errors.SEC_E_OK);
        }       
      } while(serverRc != W32Errors.SEC_E_OK || clientRc != W32Errors.SEC_E_OK);     
      // query security context token
      HANDLEByReference phContextToken = new HANDLEByReference();
      assertEquals(W32Errors.SEC_E_OK, Secur32.INSTANCE.QuerySecurityContextToken(
          phServerContext, phContextToken));
      // release security context token
      assertTrue(Kernel32.INSTANCE.CloseHandle(phContextToken.getValue()));
      // release server context
      assertEquals(W32Errors.SEC_E_OK, Secur32.INSTANCE.DeleteSecurityContext(
          phServerContext));
      assertEquals(W32Errors.SEC_E_OK, Secur32.INSTANCE.FreeCredentialsHandle(
          phServerCredential));
View Full Code Here

    }

    @Override
    public IWindowsIdentity logonDomainUserEx(final String username, final String domain, final String password,
            final int logonType, final int logonProvider) {
        final HANDLEByReference phUser = new HANDLEByReference();
        if (!Advapi32.INSTANCE.LogonUser(username, domain, password, logonType, logonProvider, phUser)) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }
        return new WindowsIdentityImpl(phUser.getValue());
    }
View Full Code Here

        return new WindowsSecurityContextImpersonationContextImpl(this.ctx);
    }

    @Override
    public IWindowsIdentity getIdentity() {
        final HANDLEByReference phContextToken = new HANDLEByReference();
        final int rc = Secur32.INSTANCE.QuerySecurityContextToken(this.ctx, phContextToken);
        if (WinError.SEC_E_OK != rc) {
            throw new Win32Exception(rc);
        }
        return new WindowsIdentityImpl(phContextToken.getValue());
    }
View Full Code Here

        enableButton = new JButton("Enable");
        enableButton.setMnemonic('e');
        enableButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                HRESULT hResult;
                hResult = LibDwmApi.INSTANCE.DwmEnableComposition(LibDwmApi.DWM_EC_ENABLECOMPOSITION);
                System.out.println("DwmEnableComposition hResult=" + hResult.intValue());
                dumpStatus();
            }
        });

        disableButton = new JButton("Disable");
        disableButton.setMnemonic('d');
        disableButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                HRESULT hResult;
                hResult = LibDwmApi.INSTANCE.DwmEnableComposition(LibDwmApi.DWM_EC_DISABLECOMPOSITION);
                System.out.println("DwmEnableComposition hResult=" + hResult.intValue());
                dumpStatus();
            }
        });

        contentPane = new JPanel();
View Full Code Here

        frame.setVisible(true);
    }

    private void dumpStatus() {
        IntByReference pfEnabled = new IntByReference();
        HRESULT hResult = LibDwmApi.INSTANCE.DwmIsCompositionEnabled(pfEnabled);
        System.out.println("DwmIsCompositionEnabled hResult=" + hResult.intValue());
        if(hResult.intValue() == LibDwmApi.S_OK) {
            System.out.println("Desktop composition is " + (pfEnabled.getValue() != 0 ? "enabled" : "disabled"));
        }
    }
View Full Code Here

  }

  public void testLoadRegTypeLib() {
    CLSID.ByReference clsid = new CLSID.ByReference();
    // get CLSID from string, Microsoft Scripting Engine
    HRESULT hr = Ole32.INSTANCE.CLSIDFromString(new WString(
        "{420B2830-E718-11CF-893D-00A0C9054228}"), clsid);
    COMUtils.checkRC(hr);
    assertEquals(0, hr.intValue());

    // get user default lcid
    LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
    PointerByReference pWordTypeLib = new PointerByReference();
    // get typelib version 1.0
    hr = OleAuto.INSTANCE.LoadRegTypeLib(clsid, 1, 0, lcid, pWordTypeLib);
    COMUtils.checkRC(hr);
    assertEquals(0, hr.intValue());
  }
View Full Code Here

    assertEquals("{00000000-0000-0000-0000-000000000000}",
        Native.toString(lpsz));
  }

  public void testCoInitializeEx() {
    HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, 0);
    assertTrue(W32Errors.SUCCEEDED(hr.intValue())
        || hr.intValue() == W32Errors.RPC_E_CHANGED_MODE);
    if (W32Errors.SUCCEEDED(hr.intValue()))
      Ole32.INSTANCE.CoUninitialize();
  }
View Full Code Here

    if (W32Errors.SUCCEEDED(hr.intValue()))
      Ole32.INSTANCE.CoUninitialize();
  }

  public void testCoCreateInstance() {
    HRESULT hrCI = Ole32.INSTANCE.CoInitializeEx(null, 0);

    GUID guid = Ole32Util
        .getGUIDFromString("{00021401-0000-0000-C000-000000000046}"); // Shell object
    GUID riid = Ole32Util
        .getGUIDFromString("{000214EE-0000-0000-C000-000000000046}"); // IShellLinkA

    PointerByReference pDispatch = new PointerByReference();

    HRESULT hr = Ole32.INSTANCE.CoCreateInstance(guid, null, // pOuter =
                                  // null, no
                                  // aggregation
        WTypes.CLSCTX_LOCAL_SERVER, riid, pDispatch);
    assertTrue(W32Errors.SUCCEEDED(hr.intValue()));
    assertTrue(!pDispatch.equals(Pointer.NULL));
    // We leak this iUnknown reference because we don't have the JNACOM lib
    // here to wrap the native iUnknown pointer and call iUnknown.release()
    if (W32Errors.SUCCEEDED(hrCI.intValue()))
      Ole32.INSTANCE.CoUninitialize();
View Full Code Here

TOP

Related Classes of com.sun.jna.platform.win32.WinNT.HANDLEByReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.