Search in sources :

Example 61 with IntByReference

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

the class Kernel32Test method testProcessIdToSessionId.

public void testProcessIdToSessionId() {
    int myProcessID = Kernel32.INSTANCE.GetCurrentProcessId();
    IntByReference pSessionId = new IntByReference();
    boolean result = Kernel32.INSTANCE.ProcessIdToSessionId(myProcessID, pSessionId);
    // should give us our session ID
    assertTrue("ProcessIdToSessionId should return true.", result);
    // on Win Vista and later we'll never be session 0
    // due to service isolation
    // anything negative would be a definite error.
    assertTrue("Session should be 1 or higher because of service isolation", pSessionId.getValue() > 0);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference)

Example 62 with IntByReference

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

the class HybdridCOMInvocationTest method testOfficeInvocationDemonstration.

public void testOfficeInvocationDemonstration() {
    // THIS IS NOT A TEST
    //
    // This reproduces the problem by using the dispatch directly.
    PointerByReference pDispatch = new PointerByReference();
    HRESULT hr = Ole32.INSTANCE.CoCreateInstance(CLSID_WORD, null, WTypes.CLSCTX_SERVER, IID_APPLICATION, pDispatch);
    if (!COMUtils.SUCCEEDED(hr)) {
        LOG.log(Level.INFO, "HybdridCOMInvocationTest test was not run, MS Word object could not be instantiated.");
        return;
    }
    Dispatch dp = new Dispatch(pDispatch.getValue());
    // DispID of InchesToPoints
    DISPID dispId = new OaIdl.DISPID(0x00000172);
    // Interface _Application of MS Word type library
    WinDef.LCID LOCALE_SYSTEM_DEFAULT = Kernel32.INSTANCE.GetSystemDefaultLCID();
    Variant.VARIANT.ByReference result = new Variant.VARIANT.ByReference();
    OaIdl.EXCEPINFO.ByReference pExcepInfo = new OaIdl.EXCEPINFO.ByReference();
    IntByReference puArgErr = new IntByReference();
    WORD wFlagsMethod = new WinDef.WORD(OleAuto.DISPATCH_METHOD);
    WORD wFlagsGet = new WinDef.WORD(OleAuto.DISPATCH_PROPERTYGET);
    WORD wFlagsCombined = new WinDef.WORD(OleAuto.DISPATCH_METHOD | OleAuto.DISPATCH_PROPERTYGET);
    OleAuto.DISPPARAMS.ByReference pDispParams = new OleAuto.DISPPARAMS.ByReference();
    VARIANT[] params = new VARIANT[] { new VARIANT(1f) };
    pDispParams.setArgs(params);
    // Call InchesToPoints as a method
    hr = dp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, wFlagsMethod, pDispParams, result, pExcepInfo, puArgErr);
    assertTrue(COMUtils.FAILED(hr));
    // Call InchesToPoints as a property getter
    hr = dp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, wFlagsGet, pDispParams, result, pExcepInfo, puArgErr);
    assertTrue(COMUtils.FAILED(hr));
    // Call InchesToPoints as a hybrid
    hr = dp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, wFlagsCombined, pDispParams, result, pExcepInfo, puArgErr);
    assertTrue(COMUtils.SUCCEEDED(hr));
    assertEquals(72.0f, result.floatValue());
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) WORD(com.sun.jna.platform.win32.WinDef.WORD) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) DISPID(com.sun.jna.platform.win32.OaIdl.DISPID) Dispatch(com.sun.jna.platform.win32.COM.Dispatch) REFIID(com.sun.jna.platform.win32.Guid.REFIID) PointerByReference(com.sun.jna.ptr.PointerByReference) IntByReference(com.sun.jna.ptr.IntByReference) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) Variant(com.sun.jna.platform.win32.Variant) OleAuto(com.sun.jna.platform.win32.OleAuto) PointerByReference(com.sun.jna.ptr.PointerByReference) WinDef(com.sun.jna.platform.win32.WinDef) OaIdl(com.sun.jna.platform.win32.OaIdl)

Example 63 with IntByReference

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

the class Netapi32Test method testNetUserEnum.

public void testNetUserEnum() {
    PointerByReference bufptr = new PointerByReference();
    IntByReference entriesread = new IntByReference();
    IntByReference totalentries = new IntByReference();
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserEnum(null, 1, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries, null));
    USER_INFO_1 userinfo = new USER_INFO_1(bufptr.getValue());
    USER_INFO_1[] userinfos = (USER_INFO_1[]) userinfo.toArray(entriesread.getValue());
    for (USER_INFO_1 ui : userinfos) {
        assertTrue(ui.usri1_name.length() > 0);
    }
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) USER_INFO_1(com.sun.jna.platform.win32.LMAccess.USER_INFO_1)

Example 64 with IntByReference

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

the class Netapi32Test method testNetGetJoinInformation.

public void testNetGetJoinInformation() {
    IntByReference bufferType = new IntByReference();
    assertEquals(W32Errors.ERROR_INVALID_PARAMETER, Netapi32.INSTANCE.NetGetJoinInformation(null, null, bufferType));
    PointerByReference lpNameBuffer = new PointerByReference();
    assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetGetJoinInformation(null, lpNameBuffer, bufferType));
    assertTrue(lpNameBuffer.getValue().getString(0).length() > 0);
    assertTrue(bufferType.getValue() > 0);
    assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue()));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 65 with IntByReference

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

the class Netapi32Test method testNetUserGetLocalGroups.

public void testNetUserGetLocalGroups() {
    String currentUser = Secur32Util.getUserNameEx(EXTENDED_NAME_FORMAT.NameSamCompatible);
    PointerByReference bufptr = new PointerByReference();
    IntByReference entriesread = new IntByReference();
    IntByReference totalentries = new IntByReference();
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserGetLocalGroups(null, currentUser, 0, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries));
    LOCALGROUP_USERS_INFO_0 lgroup = new LOCALGROUP_USERS_INFO_0(bufptr.getValue());
    LOCALGROUP_USERS_INFO_0[] lgroups = (LOCALGROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
    for (LOCALGROUP_USERS_INFO_0 localGroupInfo : lgroups) {
        assertTrue(localGroupInfo.lgrui0_name.length() > 0);
    }
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) LOCALGROUP_USERS_INFO_0(com.sun.jna.platform.win32.LMAccess.LOCALGROUP_USERS_INFO_0)

Aggregations

IntByReference (com.sun.jna.ptr.IntByReference)199 PointerByReference (com.sun.jna.ptr.PointerByReference)38 Memory (com.sun.jna.Memory)33 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)26 File (java.io.File)19 Pointer (com.sun.jna.Pointer)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)14 PSID (com.sun.jna.platform.win32.WinNT.PSID)13 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)11 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)11 HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)9 ACL (com.sun.jna.platform.win32.WinNT.ACL)8 Advapi32 (com.sun.jna.platform.win32.Advapi32)7 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)7 ACCESS_ALLOWED_ACE (com.sun.jna.platform.win32.WinNT.ACCESS_ALLOWED_ACE)6 SECURITY_DESCRIPTOR (com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)6 HKEY (com.sun.jna.platform.win32.WinReg.HKEY)6 EVT_HANDLE (com.sun.jna.platform.win32.Winevt.EVT_HANDLE)6 CredHandle (com.sun.jna.platform.win32.Sspi.CredHandle)5