use of com.sun.jna.platform.win32.COM.COMException in project jna by java-native-access.
the class ProxyObject method queryInterface.
@Override
public <T> T queryInterface(Class<T> comInterface) throws COMException {
assert COMUtils.comIsInitialized() : "COM not initialized";
try {
ComInterface comInterfaceAnnotation = comInterface.getAnnotation(ComInterface.class);
if (null == comInterfaceAnnotation) {
throw new COMException("queryInterface: Interface must define a value for iid via the ComInterface annotation");
}
final IID iid = this.getIID(comInterfaceAnnotation);
final PointerByReference ppvObject = new PointerByReference();
HRESULT hr = ProxyObject.this.getRawDispatch().QueryInterface(new REFIID(iid), ppvObject);
if (WinNT.S_OK.equals(hr)) {
Dispatch dispatch = new Dispatch(ppvObject.getValue());
T t = this.factory.createProxy(comInterface, dispatch);
// QueryInterface returns a COM object pointer with a +1
// reference, we must drop one,
// Note: createProxy adds one;
int n = dispatch.Release();
return t;
} else {
String formatMessageFromHR = Kernel32Util.formatMessage(hr);
throw new COMException("queryInterface: " + formatMessageFromHR);
}
} catch (Exception e) {
throw new COMException("Error occured when trying to query for interface " + comInterface.getName(), e);
}
}
Aggregations