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