use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.
the class MSWord method insertText.
public void insertText(String text) throws COMException {
Selection pSelection = new Selection(this.getAutomationProperty("Selection", this.getIDispatch()));
this.invokeNoReply("TypeText", pSelection, new VARIANT(text));
}
use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.
the class MSWord method Save.
public void Save(boolean bNoPrompt, LONG originalFormat) throws COMException {
VARIANT vtNoPrompt = new VARIANT(bNoPrompt);
VARIANT vtOriginalFormat = new VARIANT(originalFormat);
this.invokeNoReply("Save", this.getDocuments(), vtNoPrompt, vtOriginalFormat);
}
use of com.sun.jna.platform.win32.COM.COMException 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;
}
use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.
the class ProxyObject method advise.
public IComEventCallbackCookie advise(Class<?> comEventCallbackInterface, final IComEventCallbackListener comEventCallbackListener) {
assert COMUtils.comIsInitialized() : "COM not initialized";
try {
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");
}
final IID iid = this.getIID(comInterfaceAnnotation);
final ConnectionPoint rawCp = this.fetchRawConnectionPoint(iid);
// create the dispatch listener
final IDispatchCallback rawListener = factory.createDispatchCallback(comEventCallbackInterface, comEventCallbackListener);
// store it the comEventCallback argument, so it is not garbage
// collected.
comEventCallbackListener.setDispatchCallbackListener(rawListener);
// set the dispatch listener to listen to events from the connection
// point
final DWORDByReference pdwCookie = new DWORDByReference();
HRESULT hr = rawCp.Advise(rawListener, pdwCookie);
// release before check in case check
int n = rawCp.Release();
// throws exception
COMUtils.checkRC(hr);
// return the cookie so that a call to stop listening can be made
return new ComEventCallbackCookie(pdwCookie.getValue());
} catch (Exception e) {
throw new COMException("Error occured in advise when trying to connect the listener " + comEventCallbackListener, e);
}
}
use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.
the class ProxyObject method unadvise.
public void unadvise(Class<?> comEventCallbackInterface, final IComEventCallbackCookie cookie) {
assert COMUtils.comIsInitialized() : "COM not initialized";
try {
ComInterface comInterfaceAnnotation = comEventCallbackInterface.getAnnotation(ComInterface.class);
if (null == comInterfaceAnnotation) {
throw new COMException("unadvise: Interface must define a value for iid via the ComInterface annotation");
}
IID iid = this.getIID(comInterfaceAnnotation);
final ConnectionPoint rawCp = this.fetchRawConnectionPoint(iid);
HRESULT hr = rawCp.Unadvise(((ComEventCallbackCookie) cookie).getValue());
rawCp.Release();
COMUtils.checkRC(hr);
} catch (Exception e) {
throw new COMException("Error occured in unadvise when trying to disconnect the listener from " + this, e);
}
}
Aggregations