Search in sources :

Example 61 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project dukescript-presenters by dukescript.

the class WebKitPresenter method loadScript.

@Override
public void loadScript(Reader code) throws Exception {
    StringBuilder sb = new StringBuilder();
    for (; ; ) {
        int ch = code.read();
        if (ch == -1) {
            break;
        }
        sb.append((char) ch);
    }
    Pointer script = shell.jsc().JSStringCreateWithUTF8CString(sb.toString());
    PointerByReference ex = new PointerByReference();
    shell.jsc().JSEvaluateScript(ctx, script, null, null, 1, ex);
    shell.jsc().JSStringRelease(script);
    if (ex.getValue() != null) {
        throw new Exception(convertToString(shell.jsc(), ex.getValue()));
    }
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) Pointer(com.sun.jna.Pointer)

Example 62 with PointerByReference

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

the class ComEventCallbacksObjectFactory_Test method testComEventCallback.

@Test
public void testComEventCallback() {
    DWebBrowserEvents2_Listener listener = new DWebBrowserEvents2_Listener();
    CallbackProxy proxy = new CallbackProxy(factory, DWebBrowserEvents2.class, listener);
    REFIID refiid = new REFIID(new IID(DWebBrowserEvents2.IID));
    // precondition: the structures for the listenedToRiid and
    // refiid have to be different (else the PointerType#equals would
    // be enough
    assertFalse(proxy.listenedToRiid.getPointer().equals(refiid.getPointer()));
    // Neverthe less, the QueryInterface method has to return the
    // correct pointer (the IID is relevant, not its wrapper
    PointerByReference interfacePointer = new PointerByReference();
    // Check the "business" interface
    HRESULT hr = proxy.QueryInterface(refiid, interfacePointer);
    assertTrue(COMUtils.SUCCEEDED(hr));
    assertEquals(interfacePointer.getValue(), proxy.getPointer());
    // IUnknown must be implemented
    hr = proxy.QueryInterface(new REFIID(IID_IUNKNOWN), interfacePointer);
    assertTrue(COMUtils.SUCCEEDED(hr));
    assertEquals(interfacePointer.getValue(), proxy.getPointer());
    // Currently only Dispatch based callbacks are supported,
    // so this interface must be present to
    hr = proxy.QueryInterface(new REFIID(IID_IDISPATCH), interfacePointer);
    assertTrue(COMUtils.SUCCEEDED(hr));
    assertEquals(interfacePointer.getValue(), proxy.getPointer());
    // Negative check -- this has to fail, the IID should not be
    // assigned
    hr = proxy.QueryInterface(new REFIID(new IID("{00000000-0000-0000-C000-000000000000}")), interfacePointer);
    assertTrue(COMUtils.FAILED(hr));
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) PointerByReference(com.sun.jna.ptr.PointerByReference) REFIID(com.sun.jna.platform.win32.Guid.REFIID) Test(org.junit.Test)

Example 63 with PointerByReference

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

the class Ole32Test method testCoCreateInstance.

public void testCoCreateInstance() {
    HRESULT hrCI = Ole32.INSTANCE.CoInitializeEx(null, 0);
    GUID guid = Ole32Util.getGUIDFromString(// Shell object
    "{00021401-0000-0000-C000-000000000046}");
    GUID riid = Ole32Util.getGUIDFromString(// IShellLinkA
    "{000214EE-0000-0000-C000-000000000046}");
    PointerByReference pDispatch = new PointerByReference();
    HRESULT hr = // pOuter =
    Ole32.INSTANCE.CoCreateInstance(// pOuter =
    guid, // pOuter =
    null, // aggregation
    WTypes.CLSCTX_LOCAL_SERVER, riid, pDispatch);
    assertTrue(W32Errors.SUCCEEDED(hr.intValue()));
    assertTrue(!pDispatch.equals(Pointer.NULL));
    // here to wrap the native iUnknown pointer and call iUnknown.release()
    if (W32Errors.SUCCEEDED(hrCI.intValue()))
        Ole32.INSTANCE.CoUninitialize();
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) GUID(com.sun.jna.platform.win32.Guid.GUID)

Example 64 with PointerByReference

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

the class Netapi32Test method testNetGetDCName.

public void testNetGetDCName() {
    PointerByReference lpNameBuffer = new PointerByReference();
    IntByReference BufferType = new IntByReference();
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetGetJoinInformation(null, lpNameBuffer, BufferType));
    if (BufferType.getValue() == LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName) {
        PointerByReference bufptr = new PointerByReference();
        assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetGetDCName(null, null, bufptr));
        String dc = bufptr.getValue().getString(0);
        assertTrue(dc.length() > 0);
        assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
    }
    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 PointerByReference

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

the class Netapi32Test method testNetUserGetGroups.

public void testNetUserGetGroups() {
    User[] users = Netapi32Util.getUsers();
    assertTrue(users.length >= 1);
    PointerByReference bufptr = new PointerByReference();
    IntByReference entriesread = new IntByReference();
    IntByReference totalentries = new IntByReference();
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserGetGroups(null, users[0].name, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries));
    GROUP_USERS_INFO_0 lgroup = new GROUP_USERS_INFO_0(bufptr.getValue());
    GROUP_USERS_INFO_0[] lgroups = (GROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
    for (GROUP_USERS_INFO_0 localGroupInfo : lgroups) {
        assertTrue(localGroupInfo.grui0_name.length() > 0);
    }
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) User(com.sun.jna.platform.win32.Netapi32Util.User) GROUP_USERS_INFO_0(com.sun.jna.platform.win32.LMAccess.GROUP_USERS_INFO_0) LOCALGROUP_USERS_INFO_0(com.sun.jna.platform.win32.LMAccess.LOCALGROUP_USERS_INFO_0) PointerByReference(com.sun.jna.ptr.PointerByReference)

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