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());
}
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;
}
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());
}
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());
}
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;
}
Aggregations