Search in sources :

Example 11 with COMException

use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.

the class ProxyObject method resolveDispId.

protected DISPID resolveDispId(final IDispatch pDisp, String name) {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    if (pDisp == null)
        throw new COMException("pDisp (IDispatch) parameter is null!");
    // variable declaration
    final WString[] ptName = new WString[] { new WString(name) };
    final DISPIDByReference pdispID = new DISPIDByReference();
    // Get DISPID for name passed...
    HRESULT hr = pDisp.GetIDsOfNames(new REFIID(Guid.IID_NULL), ptName, 1, factory.getLCID(), pdispID);
    COMUtils.checkRC(hr);
    return pdispID.getValue();
}
Also used : WString(com.sun.jna.WString) COMException(com.sun.jna.platform.win32.COM.COMException) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) DISPIDByReference(com.sun.jna.platform.win32.OaIdl.DISPIDByReference) REFIID(com.sun.jna.platform.win32.Guid.REFIID)

Example 12 with COMException

use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.

the class ProxyObject method getUnknownId.

private long getUnknownId() {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    if (-1 == this.unknownId) {
        try {
            final PointerByReference ppvObject = new PointerByReference();
            Thread current = Thread.currentThread();
            String tn = current.getName();
            IID iid = com.sun.jna.platform.win32.COM.IUnknown.IID_IUNKNOWN;
            HRESULT hr = ProxyObject.this.getRawDispatch().QueryInterface(new REFIID(iid), ppvObject);
            if (WinNT.S_OK.equals(hr)) {
                Dispatch dispatch = new Dispatch(ppvObject.getValue());
                this.unknownId = Pointer.nativeValue(dispatch.getPointer());
                // QueryInterface returns a COM object pointer with a +1
                // reference, we must drop one,
                // Note: createProxy adds one;
                int n = dispatch.Release();
            } else {
                String formatMessageFromHR = Kernel32Util.formatMessage(hr);
                throw new COMException("getUnknownId: " + formatMessageFromHR);
            }
        } catch (Exception e) {
            throw new COMException("Error occured when trying get Unknown Id ", e);
        }
    }
    return this.unknownId;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) COMException(com.sun.jna.platform.win32.COM.COMException) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) PointerByReference(com.sun.jna.ptr.PointerByReference) Dispatch(com.sun.jna.platform.win32.COM.Dispatch) IDispatch(com.sun.jna.platform.win32.COM.IDispatch) WString(com.sun.jna.WString) REFIID(com.sun.jna.platform.win32.Guid.REFIID) ConnectionPoint(com.sun.jna.platform.win32.COM.ConnectionPoint) TimeoutException(java.util.concurrent.TimeoutException) COMException(com.sun.jna.platform.win32.COM.COMException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException)

Example 13 with COMException

use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.

the class RunningObjectTable method getActiveObjectsByInterface.

@Override
public <T> List<T> getActiveObjectsByInterface(Class<T> comInterface) {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    List<T> result = new ArrayList<T>();
    for (IDispatch obj : this.enumRunning()) {
        try {
            T dobj = obj.queryInterface(comInterface);
            result.add(dobj);
        } catch (COMException ex) {
        }
    }
    return result;
}
Also used : WinNT(com.sun.jna.platform.win32.WinNT) COMException(com.sun.jna.platform.win32.COM.COMException) ArrayList(java.util.ArrayList)

Example 14 with COMException

use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.

the class CallbackProxy method createRIID.

REFIID createRIID(Class<?> comEventCallbackInterface) {
    ComInterface comInterfaceAnnotation = comEventCallbackInterface.getAnnotation(ComInterface.class);
    if (null == comInterfaceAnnotation) {
        throw new COMException("advise: Interface must define a value for either iid via the ComInterface annotation");
    }
    String iidStr = comInterfaceAnnotation.iid();
    if (null == iidStr || iidStr.isEmpty()) {
        throw new COMException("ComInterface must define a value for iid");
    }
    return new REFIID(new IID(iidStr).getPointer());
}
Also used : COMException(com.sun.jna.platform.win32.COM.COMException) IID(com.sun.jna.platform.win32.Guid.IID) REFIID(com.sun.jna.platform.win32.Guid.REFIID) WString(com.sun.jna.WString) REFIID(com.sun.jna.platform.win32.Guid.REFIID) ComInterface(com.sun.jna.platform.win32.COM.util.annotation.ComInterface)

Example 15 with COMException

use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.

the class ObjectFactory method discoverClsId.

GUID discoverClsId(ComObject annotation) {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    String clsIdStr = annotation.clsId();
    final String progIdStr = annotation.progId();
    if (null != clsIdStr && !clsIdStr.isEmpty()) {
        return new CLSID(clsIdStr);
    } else if (null != progIdStr && !progIdStr.isEmpty()) {
        final CLSID.ByReference rclsid = new CLSID.ByReference();
        WinNT.HRESULT hr = Ole32.INSTANCE.CLSIDFromProgID(progIdStr, rclsid);
        COMUtils.checkRC(hr);
        return rclsid;
    } else {
        throw new COMException("ComObject must define a value for either clsId or progId");
    }
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) COMException(com.sun.jna.platform.win32.COM.COMException) CLSID(com.sun.jna.platform.win32.Guid.CLSID) PointerByReference(com.sun.jna.ptr.PointerByReference)

Aggregations

COMException (com.sun.jna.platform.win32.COM.COMException)13 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)13 REFIID (com.sun.jna.platform.win32.Guid.REFIID)10 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)8 PointerByReference (com.sun.jna.ptr.PointerByReference)7 WString (com.sun.jna.WString)5 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)5 IID (com.sun.jna.platform.win32.Guid.IID)5 WinNT (com.sun.jna.platform.win32.WinNT)5 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)4 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)4 ComInterface (com.sun.jna.platform.win32.COM.util.annotation.ComInterface)4 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 ComObject (com.sun.jna.platform.win32.COM.util.annotation.ComObject)3 GUID (com.sun.jna.platform.win32.Guid.GUID)2 EXCEPINFO (com.sun.jna.platform.win32.OaIdl.EXCEPINFO)2 DISPPARAMS (com.sun.jna.platform.win32.OleAuto.DISPPARAMS)2