Package com.sun.jna.ptr

Examples of com.sun.jna.ptr.IntByReference


* @author dblock[at]dblock.org
*/
public abstract class WinspoolUtil {

    public static PRINTER_INFO_1[] getPrinterInfo1() {
        IntByReference pcbNeeded = new IntByReference();
        IntByReference pcReturned = new IntByReference();
        Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 1,
                null, 0, pcbNeeded, pcReturned);
        if (pcbNeeded.getValue() <= 0) {
            return new PRINTER_INFO_1[0];
        }

        PRINTER_INFO_1 pPrinterEnum = new PRINTER_INFO_1(pcbNeeded.getValue());
        if (!Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null,
                1, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded,
                pcReturned)) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }

        pPrinterEnum.read();

        return (PRINTER_INFO_1[]) pPrinterEnum.toArray(pcReturned.getValue());
    }
View Full Code Here


        return (PRINTER_INFO_1[]) pPrinterEnum.toArray(pcReturned.getValue());
    }

    public static PRINTER_INFO_4[] getPrinterInfo4() {
        IntByReference pcbNeeded = new IntByReference();
        IntByReference pcReturned = new IntByReference();
        Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null, 4,
                null, 0, pcbNeeded, pcReturned);
        if (pcbNeeded.getValue() <= 0) {
            return new PRINTER_INFO_4[0];
        }

        PRINTER_INFO_4 pPrinterEnum = new PRINTER_INFO_4(pcbNeeded.getValue());
        if (!Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL, null,
                4, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded,
                pcReturned)) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }

        pPrinterEnum.read();

        return (PRINTER_INFO_4[]) pPrinterEnum.toArray(pcReturned.getValue());
    }
View Full Code Here

        return (PRINTER_INFO_4[]) pPrinterEnum.toArray(pcReturned.getValue());
    }

    public static JOB_INFO_1[] getJobInfo1(HANDLEByReference phPrinter) {
        IntByReference pcbNeeded = new IntByReference();
        IntByReference pcReturned = new IntByReference();
        Winspool.INSTANCE.EnumJobs(phPrinter.getValue(), 0, 255, 1, null, 0,
                pcbNeeded, pcReturned);
        if (pcbNeeded.getValue() <= 0) {
            return new JOB_INFO_1[0];
        }

        JOB_INFO_1 pJobEnum = new JOB_INFO_1(pcbNeeded.getValue());
        if (!Winspool.INSTANCE.EnumJobs(phPrinter.getValue(), 0, 255, 1,
                pJobEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded,
                pcReturned)) {
            throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
        }

        pJobEnum.read();

        return (JOB_INFO_1[]) pJobEnum.toArray(pcReturned.getValue());
    }
View Full Code Here

        //System.out.println("GetRefTypeOfImplType: " + pRefType.toString());
    }

    public void testGetImplTypeFlags() {
        ITypeInfo typeInfo = getTypeInfo();
        IntByReference pImplTypeFlags = new IntByReference();
        HRESULT hr = typeInfo.GetImplTypeFlags(new UINT(0), pImplTypeFlags);

        COMUtils.checkRC(hr);
        assertEquals(0, hr.intValue());
        //System.out.println("GetImplTypeFlags: " + pImplTypeFlags.toString());
View Full Code Here

   *            Token.
   * @return Token user.
   */
  public static Account getTokenAccount(HANDLE hToken) {
    // get token group information size
    IntByReference tokenInformationLength = new IntByReference();
    if (Advapi32.INSTANCE.GetTokenInformation(hToken,
        WinNT.TOKEN_INFORMATION_CLASS.TokenUser, null, 0,
        tokenInformationLength)) {
      throw new RuntimeException(
          "Expected GetTokenInformation to fail with ERROR_INSUFFICIENT_BUFFER");
    }
    int rc = Kernel32.INSTANCE.GetLastError();
    if (rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
      throw new Win32Exception(rc);
    }
    // get token user information
    WinNT.TOKEN_USER user = new WinNT.TOKEN_USER(
        tokenInformationLength.getValue());
    if (!Advapi32.INSTANCE.GetTokenInformation(hToken,
        WinNT.TOKEN_INFORMATION_CLASS.TokenUser, user,
        tokenInformationLength.getValue(), tokenInformationLength)) {
      throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
    }
    return getAccountBySid(user.User.Sid);
  }
View Full Code Here

      case W32Errors.ERROR_FILE_NOT_FOUND:
        return false;
      default:
        throw new Win32Exception(rc);
      }
      IntByReference lpcbData = new IntByReference();
      IntByReference lpType = new IntByReference();
      rc = Advapi32.INSTANCE.RegQueryValueEx(phkKey.getValue(), value, 0,
          lpType, (char[]) null, lpcbData);
      switch (rc) {
      case W32Errors.ERROR_SUCCESS:
      case W32Errors.ERROR_MORE_DATA:
View Full Code Here

   * @param value
   *            Name of the value to retrieve.
   * @return String value.
   */
  public static String registryGetStringValue(HKEY hKey, String value) {
    IntByReference lpcbData = new IntByReference();
    IntByReference lpType = new IntByReference();
    int rc = Advapi32.INSTANCE.RegQueryValueEx(hKey, value, 0,
        lpType, (char[]) null, lpcbData);
    if (rc != W32Errors.ERROR_SUCCESS
        && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
      throw new Win32Exception(rc);
    }
    if (lpType.getValue() != WinNT.REG_SZ
        && lpType.getValue() != WinNT.REG_EXPAND_SZ) {
      throw new RuntimeException("Unexpected registry type "
          + lpType.getValue()
          + ", expected REG_SZ or REG_EXPAND_SZ");
    }
    char[] data = new char[lpcbData.getValue()];
    rc = Advapi32.INSTANCE.RegQueryValueEx(hKey, value, 0,
        lpType, data, lpcbData);
View Full Code Here

   * @param value
   *            Name of the value to retrieve.
   * @return String value.
   */
  public static String registryGetExpandableStringValue(HKEY hKey, String value) {
    IntByReference lpcbData = new IntByReference();
    IntByReference lpType = new IntByReference();
    int rc = Advapi32.INSTANCE.RegQueryValueEx(hKey, value, 0,
        lpType, (char[]) null, lpcbData);
    if (rc != W32Errors.ERROR_SUCCESS
        && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
      throw new Win32Exception(rc);
    }
    if (lpType.getValue() != WinNT.REG_EXPAND_SZ) {
      throw new RuntimeException("Unexpected registry type "
          + lpType.getValue() + ", expected REG_SZ");
    }
    char[] data = new char[lpcbData.getValue()];
    rc = Advapi32.INSTANCE.RegQueryValueEx(hKey, value, 0,
        lpType, data, lpcbData);
    if (rc != W32Errors.ERROR_SUCCESS
View Full Code Here

   * @param value
   *            Name of the value to retrieve.
   * @return String value.
   */
  public static String[] registryGetStringArray(HKEY hKey, String value) {
    IntByReference lpcbData = new IntByReference();
    IntByReference lpType = new IntByReference();
    int rc = Advapi32.INSTANCE.RegQueryValueEx(hKey, value, 0,
        lpType, (char[]) null, lpcbData);
    if (rc != W32Errors.ERROR_SUCCESS
        && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
      throw new Win32Exception(rc);
    }
    if (lpType.getValue() != WinNT.REG_MULTI_SZ) {
      throw new RuntimeException("Unexpected registry type "
          + lpType.getValue() + ", expected REG_SZ");
    }
    Memory data = new Memory(lpcbData.getValue());
    rc = Advapi32.INSTANCE.RegQueryValueEx(hKey, value, 0,
        lpType, data, lpcbData);
    if (rc != W32Errors.ERROR_SUCCESS
View Full Code Here

   * @param value
   *            Name of the value to retrieve.
   * @return String value.
   */
  public static byte[] registryGetBinaryValue(HKEY hKey, String value) {
    IntByReference lpcbData = new IntByReference();
    IntByReference lpType = new IntByReference();
    int rc = Advapi32.INSTANCE.RegQueryValueEx(hKey, value, 0,
        lpType, (char[]) null, lpcbData);
    if (rc != W32Errors.ERROR_SUCCESS
        && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
      throw new Win32Exception(rc);
    }
    if (lpType.getValue() != WinNT.REG_BINARY) {
      throw new RuntimeException("Unexpected registry type "
          + lpType.getValue() + ", expected REG_BINARY");
    }
    byte[] data = new byte[lpcbData.getValue()];
    rc = Advapi32.INSTANCE.RegQueryValueEx(hKey, value, 0,
        lpType, data, lpcbData);
    if (rc != W32Errors.ERROR_SUCCESS
View Full Code Here

TOP

Related Classes of com.sun.jna.ptr.IntByReference

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.