Search in sources :

Example 6 with GUID

use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.

the class COMBindingBaseObject method init.

private void init(boolean useActiveInstance, GUID clsid, int dwClsContext) throws COMException {
    HRESULT hr;
    if (useActiveInstance) {
        hr = OleAuto.INSTANCE.GetActiveObject(clsid, null, this.pUnknown);
        if (COMUtils.SUCCEEDED(hr)) {
            this.iUnknown = new Unknown(this.pUnknown.getValue());
            hr = iUnknown.QueryInterface(new REFIID(IDispatch.IID_IDISPATCH), this.pDispatch);
        } else {
            hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, dwClsContext, IDispatch.IID_IDISPATCH, this.pDispatch);
        }
    } else {
        hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, dwClsContext, IDispatch.IID_IDISPATCH, this.pDispatch);
    }
    COMUtils.checkRC(hr);
    this.iDispatch = new Dispatch(this.pDispatch.getValue());
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) REFIID(com.sun.jna.platform.win32.Guid.REFIID)

Example 7 with GUID

use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.

the class GuidTest method testBehaviourWithOle32.

/**
	 * Instantiates two guids, one with windows build-in function and one via
	 * jna and compares it.
	 */
public void testBehaviourWithOle32() {
    GUID ole32Guid = Ole32Util.getGUIDFromString("{A5DCBF10-6530-11D2-901F-00C04FB951ED}");
    GUID jnaGuid = new GUID("{A5DCBF10-6530-11D2-901F-00C04FB951ED}");
    assertEquals(ole32Guid, jnaGuid);
}
Also used : GUID(com.sun.jna.platform.win32.Guid.GUID)

Example 8 with GUID

use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.

the class GuidTest method testGUIDFromString2.

/**
	 * Loads a GUID from string via the constructor and verify that the guid
	 * returned has the expected values in each byte.
	 */
public void testGUIDFromString2() {
    String sourceGuidStr = "{A5DCBF10-6530-11D2-901F-00C04FB951ED}";
    // test loading via constructor
    GUID targetGuid = new GUID(sourceGuidStr);
    assertEquals(targetGuid.toGuidString(), sourceGuidStr);
}
Also used : GUID(com.sun.jna.platform.win32.Guid.GUID)

Example 9 with GUID

use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.

the class GuidTest method testGUIDFromBinary.

/**
	 * Loads a GUID from a byte array and verify that the guid returned has the
	 * expected values in each byte.
	 */
public void testGUIDFromBinary() {
    byte[] sourceGuidBArr = new byte[] { (byte) 0xA5, (byte) 0xDC, (byte) 0xBF, (byte) 0x10, (byte) 0x65, (byte) 0x30, (byte) 0x11, (byte) 0xD2, (byte) 0x90, (byte) 0x1F, (byte) 0x00, (byte) 0xC0, (byte) 0x4F, (byte) 0xB9, (byte) 0x51, (byte) 0xED };
    // test loading via static method
    GUID targetGuid = GUID.fromBinary(sourceGuidBArr);
    byte[] targetGuidBArr = targetGuid.toByteArray();
    for (int i = 0; i < sourceGuidBArr.length; i++) {
        assertEquals(targetGuidBArr[i], sourceGuidBArr[i]);
    }
}
Also used : GUID(com.sun.jna.platform.win32.Guid.GUID)

Example 10 with GUID

use of com.sun.jna.platform.win32.Guid.GUID in project jna by java-native-access.

the class ObjectFactory method fetchObject.

/**
	 * Gets and existing COM object (GetActiveObject) for the given progId and
	 * returns a ProxyObject for the given interface.
	 */
public <T> T fetchObject(Class<T> comInterface) {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    ComObject comObectAnnotation = comInterface.getAnnotation(ComObject.class);
    if (null == comObectAnnotation) {
        throw new COMException("createObject: Interface must define a value for either clsId or progId via the ComInterface annotation");
    }
    final GUID guid = this.discoverClsId(comObectAnnotation);
    final PointerByReference ptrDisp = new PointerByReference();
    WinNT.HRESULT hr = OleAuto.INSTANCE.GetActiveObject(guid, null, ptrDisp);
    COMUtils.checkRC(hr);
    Dispatch d = new Dispatch(ptrDisp.getValue());
    T t = this.createProxy(comInterface, d);
    //GetActiveObject returns a pointer to COM object with a +1 reference count, so we must drop one
    //Note: the createProxy adds one
    d.Release();
    return t;
}
Also used : COMException(com.sun.jna.platform.win32.COM.COMException) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) WinNT(com.sun.jna.platform.win32.WinNT) PointerByReference(com.sun.jna.ptr.PointerByReference) ComObject(com.sun.jna.platform.win32.COM.util.annotation.ComObject) GUID(com.sun.jna.platform.win32.Guid.GUID) WinNT(com.sun.jna.platform.win32.WinNT) Dispatch(com.sun.jna.platform.win32.COM.Dispatch) IDispatch(com.sun.jna.platform.win32.COM.IDispatch) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT)

Aggregations

GUID (com.sun.jna.platform.win32.Guid.GUID)20 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)10 PointerByReference (com.sun.jna.ptr.PointerByReference)7 COMException (com.sun.jna.platform.win32.COM.COMException)3 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)2 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)2 ComObject (com.sun.jna.platform.win32.COM.util.annotation.ComObject)2 WinNT (com.sun.jna.platform.win32.WinNT)2 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)2 Memory (com.sun.jna.Memory)1 CLSID (com.sun.jna.platform.win32.Guid.CLSID)1 REFIID (com.sun.jna.platform.win32.Guid.REFIID)1 DomainController (com.sun.jna.platform.win32.Netapi32Util.DomainController)1 DomainTrust (com.sun.jna.platform.win32.Netapi32Util.DomainTrust)1 EVT_HANDLE (com.sun.jna.platform.win32.Winevt.EVT_HANDLE)1 IntByReference (com.sun.jna.ptr.IntByReference)1 File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1