Search in sources :

Example 86 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class ObjectFactory method getRunningObjectTable.

/**
	 * CoInitialize must be called be fore this method. Either explicitly or
	 * implicitly via other methods.
	 * 
	 * @return running object table
	 */
public IRunningObjectTable getRunningObjectTable() {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    final PointerByReference rotPtr = new PointerByReference();
    HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new WinDef.DWORD(0), rotPtr);
    COMUtils.checkRC(hr);
    com.sun.jna.platform.win32.COM.RunningObjectTable raw = new com.sun.jna.platform.win32.COM.RunningObjectTable(rotPtr.getValue());
    IRunningObjectTable rot = new RunningObjectTable(raw, this);
    return rot;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) WinDef(com.sun.jna.platform.win32.WinDef)

Example 87 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class Netapi32Util method getGlobalGroups.

/**
     * Get the names of global groups on a computer.
     * @param serverName Name of the computer.
     * @return An array of group names.
     */
public static Group[] getGlobalGroups(String serverName) {
    PointerByReference bufptr = new PointerByReference();
    IntByReference entriesRead = new IntByReference();
    IntByReference totalEntries = new IntByReference();
    try {
        int rc = Netapi32.INSTANCE.NetGroupEnum(serverName, 1, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesRead, totalEntries, null);
        if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
            throw new Win32Exception(rc);
        }
        LMAccess.GROUP_INFO_1 group = new LMAccess.GROUP_INFO_1(bufptr.getValue());
        LMAccess.GROUP_INFO_1[] groups = (LMAccess.GROUP_INFO_1[]) group.toArray(entriesRead.getValue());
        ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
        for (LMAccess.GROUP_INFO_1 lgpi : groups) {
            LocalGroup lgp = new LocalGroup();
            if (lgpi.grpi1_name != null) {
                lgp.name = lgpi.grpi1_name.toString();
            }
            if (lgpi.grpi1_comment != null) {
                lgp.comment = lgpi.grpi1_comment.toString();
            }
            result.add(lgp);
        }
        return result.toArray(new LocalGroup[0]);
    } finally {
        if (bufptr.getValue() != Pointer.NULL) {
            int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
            if (LMErr.NERR_Success != rc) {
                throw new Win32Exception(rc);
            }
        }
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) LOCALGROUP_INFO_1(com.sun.jna.platform.win32.LMAccess.LOCALGROUP_INFO_1) PointerByReference(com.sun.jna.ptr.PointerByReference) ArrayList(java.util.ArrayList)

Example 88 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class Netapi32Util method getDomainName.

/**
     * Get information about a computer.
     * @param computerName computer name
     * @return Domain or workgroup name.
     */
public static String getDomainName(String computerName) {
    PointerByReference lpNameBuffer = new PointerByReference();
    IntByReference bufferType = new IntByReference();
    try {
        int rc = Netapi32.INSTANCE.NetGetJoinInformation(computerName, lpNameBuffer, bufferType);
        if (LMErr.NERR_Success != rc) {
            throw new Win32Exception(rc);
        }
        // type of domain: bufferType.getValue()
        return lpNameBuffer.getValue().getWideString(0);
    } finally {
        if (lpNameBuffer.getPointer() != null) {
            int rc = Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue());
            if (LMErr.NERR_Success != rc) {
                throw new Win32Exception(rc);
            }
        }
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 89 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class TypeLibUtil method GetTypeComp.

/**
     * Gets the type comp.
     * 
     * @return the i type comp. by reference
     */
public TypeComp GetTypeComp() {
    PointerByReference ppTComp = new PointerByReference();
    HRESULT hr = this.typelib.GetTypeComp(ppTComp);
    COMUtils.checkRC(hr);
    return new TypeComp(ppTComp.getValue());
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 90 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class TypeLibUtil method getLibAttr.

/**
     * Gets the lib attr.
     * 
     * @return the lib attr
     */
public TLIBATTR getLibAttr() {
    PointerByReference ppTLibAttr = new PointerByReference();
    HRESULT hr = typelib.GetLibAttr(ppTLibAttr);
    COMUtils.checkRC(hr);
    return new TLIBATTR(ppTLibAttr.getValue());
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) TLIBATTR(com.sun.jna.platform.win32.OaIdl.TLIBATTR)

Aggregations

PointerByReference (com.sun.jna.ptr.PointerByReference)128 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)54 IntByReference (com.sun.jna.ptr.IntByReference)35 Pointer (com.sun.jna.Pointer)20 Test (org.junit.Test)19 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)18 REFIID (com.sun.jna.platform.win32.Guid.REFIID)13 File (java.io.File)13 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)10 PSID (com.sun.jna.platform.win32.WinNT.PSID)10 Memory (com.sun.jna.Memory)8 WString (com.sun.jna.WString)8 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)7 ULONGByReference (com.sun.jna.platform.win32.WinDef.ULONGByReference)7 WinNT (com.sun.jna.platform.win32.WinNT)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 IID (com.sun.jna.platform.win32.Guid.IID)6 ArrayList (java.util.ArrayList)6 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)5 UINT (com.sun.jna.platform.win32.WinDef.UINT)5