Search in sources :

Example 6 with REFIID

use of com.sun.jna.platform.win32.Guid.REFIID 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 REFIID

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

the class COMBindingBaseObject method oleMethod.

protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, IDispatch pDisp, DISPID dispId, VARIANT[] pArgs) throws COMException {
    if (pDisp == null)
        throw new COMException("pDisp (IDispatch) parameter is null!");
    // variable declaration
    int _argsLen = 0;
    VARIANT[] _args = null;
    DISPPARAMS.ByReference dp = new DISPPARAMS.ByReference();
    EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference();
    IntByReference puArgErr = new IntByReference();
    // make parameter reverse ordering as expected by COM runtime
    if ((pArgs != null) && (pArgs.length > 0)) {
        _argsLen = pArgs.length;
        _args = new VARIANT[_argsLen];
        int revCount = _argsLen;
        for (int i = 0; i < _argsLen; i++) {
            _args[i] = pArgs[--revCount];
        }
    }
    // Handle special-case for property-puts!
    if (nType == OleAuto.DISPATCH_PROPERTYPUT) {
        dp.setRgdispidNamedArgs(new DISPID[] { OaIdl.DISPID_PROPERTYPUT });
    }
    // Build DISPPARAMS
    if (_argsLen > 0) {
        dp.setArgs(_args);
        // write 'DISPPARAMS' structure to memory
        dp.write();
    }
    // Apply "fix" according to
    // https://www.delphitools.info/2013/04/30/gaining-visual-basic-ole-super-powers/
    // https://msdn.microsoft.com/en-us/library/windows/desktop/ms221486(v=vs.85).aspx
    //
    // Summary: there are methods in the word typelibrary that require both
    // PROPERTYGET _and_ METHOD to be set. With only one of these set the call
    // fails.
    //
    // The article from delphitools argues, that automation compatible libraries
    // need to be compatible with VisualBasic which does not distingish methods
    // and property getters and will set both flags always.
    //
    // The MSDN article advises this behaviour: "[...] Some languages cannot 
    // distinguish between retrieving a property and calling a method. In this 
    //case, you should set the flags DISPATCH_PROPERTYGET and DISPATCH_METHOD.
    // [...]"))
    //
    // This was found when trying to bind InchesToPoints from the _Application 
    // dispatch interface of the MS Word 15 type library
    //
    // The signature according the ITypeLib Viewer (OLE/COM Object Viewer):
    // [id(0x00000172), helpcontext(0x09700172)]
    // single InchesToPoints([in] single Inches);
    final int finalNType;
    if (nType == OleAuto.DISPATCH_METHOD || nType == OleAuto.DISPATCH_PROPERTYGET) {
        finalNType = OleAuto.DISPATCH_METHOD | OleAuto.DISPATCH_PROPERTYGET;
    } else {
        finalNType = nType;
    }
    // Make the call!
    HRESULT hr = pDisp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, new WinDef.WORD(finalNType), dp, pvResult, pExcepInfo, puArgErr);
    COMUtils.checkRC(hr, pExcepInfo, puArgErr);
    return hr;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) EXCEPINFO(com.sun.jna.platform.win32.OaIdl.EXCEPINFO) REFIID(com.sun.jna.platform.win32.Guid.REFIID) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) PointerByReference(com.sun.jna.ptr.PointerByReference) DISPIDByReference(com.sun.jna.platform.win32.OaIdl.DISPIDByReference) IntByReference(com.sun.jna.ptr.IntByReference) WinDef(com.sun.jna.platform.win32.WinDef) DISPPARAMS(com.sun.jna.platform.win32.OleAuto.DISPPARAMS)

Example 8 with REFIID

use of com.sun.jna.platform.win32.Guid.REFIID 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 9 with REFIID

use of com.sun.jna.platform.win32.Guid.REFIID 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 10 with REFIID

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

the class ProxyObject method fetchRawConnectionPoint.

// ---------------------- IConnectionPoint ----------------------
private ConnectionPoint fetchRawConnectionPoint(IID iid) throws InterruptedException, ExecutionException, TimeoutException {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    // query for ConnectionPointContainer
    IConnectionPointContainer cpc = this.queryInterface(IConnectionPointContainer.class);
    Dispatch rawCpcDispatch = (Dispatch) cpc.getRawDispatch();
    final ConnectionPointContainer rawCpc = new ConnectionPointContainer(rawCpcDispatch.getPointer());
    // find connection point for comEventCallback interface
    final REFIID adviseRiid = new REFIID(iid.getPointer());
    final PointerByReference ppCp = new PointerByReference();
    HRESULT hr = rawCpc.FindConnectionPoint(adviseRiid, ppCp);
    COMUtils.checkRC(hr);
    final ConnectionPoint rawCp = new ConnectionPoint(ppCp.getValue());
    return rawCp;
}
Also used : ConnectionPointContainer(com.sun.jna.platform.win32.COM.ConnectionPointContainer) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) Dispatch(com.sun.jna.platform.win32.COM.Dispatch) IDispatch(com.sun.jna.platform.win32.COM.IDispatch) REFIID(com.sun.jna.platform.win32.Guid.REFIID) ConnectionPoint(com.sun.jna.platform.win32.COM.ConnectionPoint)

Aggregations

REFIID (com.sun.jna.platform.win32.Guid.REFIID)20 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)19 PointerByReference (com.sun.jna.ptr.PointerByReference)16 WString (com.sun.jna.WString)9 IID (com.sun.jna.platform.win32.Guid.IID)7 Test (org.junit.Test)7 COMException (com.sun.jna.platform.win32.COM.COMException)6 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)6 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)6 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)4 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)4 IntByReference (com.sun.jna.ptr.IntByReference)4 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)3 EXCEPINFO (com.sun.jna.platform.win32.OaIdl.EXCEPINFO)3 DISPPARAMS (com.sun.jna.platform.win32.OleAuto.DISPPARAMS)3 WinDef (com.sun.jna.platform.win32.WinDef)3 ComInterface (com.sun.jna.platform.win32.COM.util.annotation.ComInterface)2 DISPID (com.sun.jna.platform.win32.OaIdl.DISPID)2 Variant (com.sun.jna.platform.win32.Variant)2 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)2