Search in sources :

Example 1 with CLSID

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

the class ITypeLibTest method loadShellTypeLib.

private ITypeLib loadShellTypeLib() {
    CLSID.ByReference clsid = new CLSID.ByReference();
    // get CLSID from string
    HRESULT hr = Ole32.INSTANCE.CLSIDFromString(new WString(SHELL_CLSID), clsid);
    assertTrue(COMUtils.SUCCEEDED(hr));
    // get user default lcid
    LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
    PointerByReference pShellTypeLib = new PointerByReference();
    // load typelib
    hr = OleAuto.INSTANCE.LoadRegTypeLib(clsid, SHELL_MAJOR, SHELL_MINOR, lcid, pShellTypeLib);
    assertTrue(COMUtils.SUCCEEDED(hr));
    return new TypeLib(pShellTypeLib.getValue());
}
Also used : WString(com.sun.jna.WString) LCID(com.sun.jna.platform.win32.WinDef.LCID) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) CLSID(com.sun.jna.platform.win32.Guid.CLSID) PointerByReference(com.sun.jna.ptr.PointerByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) USHORTByReference(com.sun.jna.platform.win32.WinDef.USHORTByReference)

Example 2 with CLSID

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

the class IDispatchTest method createIDispatch.

private Dispatch createIDispatch() {
    try {
        PointerByReference pDispatch = new PointerByReference();
        // Get CLSID for Shell.Application...
        CLSID.ByReference clsid = new CLSID.ByReference();
        HRESULT hr = Ole32.INSTANCE.CLSIDFromProgID("Shell.Application", clsid);
        if (W32Errors.FAILED(hr)) {
            Ole32.INSTANCE.CoUninitialize();
            COMUtils.checkRC(hr);
        }
        hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, WTypes.CLSCTX_SERVER, IDispatch.IID_IDISPATCH, pDispatch);
        if (W32Errors.FAILED(hr)) {
            COMUtils.checkRC(hr);
        }
        return new Dispatch(pDispatch.getValue());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) CLSID(com.sun.jna.platform.win32.Guid.CLSID) PointerByReference(com.sun.jna.ptr.PointerByReference) UINTByReference(com.sun.jna.platform.win32.WinDef.UINTByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) DISPIDByReference(com.sun.jna.platform.win32.OaIdl.DISPIDByReference)

Example 3 with CLSID

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

the class OleAutoTest method testLoadRegTypeLib.

public void testLoadRegTypeLib() {
    CLSID.ByReference clsid = new CLSID.ByReference();
    // get CLSID from string, Microsoft Scripting Engine
    HRESULT hr = Ole32.INSTANCE.CLSIDFromString(new WString("{420B2830-E718-11CF-893D-00A0C9054228}"), clsid);
    COMUtils.checkRC(hr);
    assertEquals(0, hr.intValue());
    // get user default lcid
    LCID lcid = Kernel32.INSTANCE.GetUserDefaultLCID();
    PointerByReference pWordTypeLib = new PointerByReference();
    // get typelib version 1.0
    hr = OleAuto.INSTANCE.LoadRegTypeLib(clsid, 1, 0, lcid, pWordTypeLib);
    COMUtils.checkRC(hr);
    assertEquals(0, hr.intValue());
}
Also used : WString(com.sun.jna.WString) LCID(com.sun.jna.platform.win32.WinDef.LCID) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) CLSID(com.sun.jna.platform.win32.Guid.CLSID) PointerByReference(com.sun.jna.ptr.PointerByReference) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 4 with CLSID

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

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

HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)8 PointerByReference (com.sun.jna.ptr.PointerByReference)7 CLSID (com.sun.jna.platform.win32.Guid.CLSID)5 COMException (com.sun.jna.platform.win32.COM.COMException)3 WString (com.sun.jna.WString)2 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 GUID (com.sun.jna.platform.win32.Guid.GUID)2 LCID (com.sun.jna.platform.win32.WinDef.LCID)2 WinNT (com.sun.jna.platform.win32.WinNT)2 EnumKey (com.sun.jna.platform.win32.Advapi32Util.EnumKey)1 InfoKey (com.sun.jna.platform.win32.Advapi32Util.InfoKey)1 COMInfo (com.sun.jna.platform.win32.COM.COMUtils.COMInfo)1 REFIID (com.sun.jna.platform.win32.Guid.REFIID)1 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)1 UINTByReference (com.sun.jna.platform.win32.WinDef.UINTByReference)1 USHORTByReference (com.sun.jna.platform.win32.WinDef.USHORTByReference)1 HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)1 File (java.io.File)1