use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class TypeLibUtil method getLibAttr.
/**
* Gets the lib attr.
*
* @return the lib attr
*/
public TLIBATTR getLibAttr() {
PointerByReference ppTLibAttr = new PointerByReference();
HRESULT hr = typelib.GetLibAttr(ppTLibAttr);
COMUtils.checkRC(hr);
return new TLIBATTR(ppTLibAttr.getValue());
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class TypeLibUtil method getDocumentation.
/**
* Gets the documentation.
*
* @param index
* the index
* @return the documentation
*/
public TypeLibDoc getDocumentation(int index) {
BSTRByReference pBstrName = new BSTRByReference();
BSTRByReference pBstrDocString = new BSTRByReference();
DWORDByReference pdwHelpContext = new DWORDByReference();
BSTRByReference pBstrHelpFile = new BSTRByReference();
HRESULT hr = typelib.GetDocumentation(index, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
COMUtils.checkRC(hr);
TypeLibDoc typeLibDoc = new TypeLibDoc(pBstrName.getString(), pBstrDocString.getString(), pdwHelpContext.getValue().intValue(), pBstrHelpFile.getString());
OLEAUTO.SysFreeString(pBstrName.getValue());
OLEAUTO.SysFreeString(pBstrDocString.getValue());
OLEAUTO.SysFreeString(pBstrHelpFile.getValue());
return typeLibDoc;
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class ProxyObject method oleMethod.
/*
* @see com.sun.jna.platform.win32.COM.COMBindingBaseObject#oleMethod
*/
protected HRESULT oleMethod(final int nType, final VARIANT.ByReference pvResult, final IDispatch pDisp, final DISPID dispId, VARIANT[] pArgs) throws COMException {
assert COMUtils.comIsInitialized() : "COM not initialized";
if (pDisp == null)
throw new COMException("pDisp (IDispatch) parameter is null!");
// variable declaration
int _argsLen = 0;
VARIANT[] _args = null;
final DISPPARAMS.ByReference dp = new DISPPARAMS.ByReference();
final EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference();
final IntByReference puArgErr = new IntByReference();
// make parameter reverse ordering as expected by COM runtime
if ((pArgs != null) && (pArgs.length > 0)) {
_argsLen = pArgs.length;
_args = new VARIANT[_argsLen];
int revCount = _argsLen;
for (int i = 0; i < _argsLen; i++) {
_args[i] = pArgs[--revCount];
}
}
// Handle special-case for property-puts!
if (nType == OleAuto.DISPATCH_PROPERTYPUT) {
dp.setRgdispidNamedArgs(new DISPID[] { OaIdl.DISPID_PROPERTYPUT });
}
// Apply "fix" according to
// https://www.delphitools.info/2013/04/30/gaining-visual-basic-ole-super-powers/
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms221486(v=vs.85).aspx
//
// Summary: there are methods in the word typelibrary that require both
// PROPERTYGET _and_ METHOD to be set. With only one of these set the call
// fails.
//
// The article from delphitools argues, that automation compatible libraries
// need to be compatible with VisualBasic which does not distingish methods
// and property getters and will set both flags always.
//
// The MSDN article advises this behaviour: "[...] Some languages cannot
// distinguish between retrieving a property and calling a method. In this
//case, you should set the flags DISPATCH_PROPERTYGET and DISPATCH_METHOD.
// [...]"))
//
// This was found when trying to bind InchesToPoints from the _Application
// dispatch interface of the MS Word 15 type library
//
// The signature according the ITypeLib Viewer (OLE/COM Object Viewer):
// [id(0x00000172), helpcontext(0x09700172)]
// single InchesToPoints([in] single Inches);
final int finalNType;
if (nType == OleAuto.DISPATCH_METHOD || nType == OleAuto.DISPATCH_PROPERTYGET) {
finalNType = OleAuto.DISPATCH_METHOD | OleAuto.DISPATCH_PROPERTYGET;
} else {
finalNType = nType;
}
// Build DISPPARAMS
if (_argsLen > 0) {
dp.setArgs(_args);
// write 'DISPPARAMS' structure to memory
dp.write();
}
HRESULT hr = pDisp.Invoke(dispId, new REFIID(Guid.IID_NULL), factory.getLCID(), new WinDef.WORD(finalNType), dp, pvResult, pExcepInfo, puArgErr);
COMUtils.checkRC(hr, pExcepInfo, puArgErr);
return hr;
}
use of com.sun.jna.platform.win32.WinNT.HRESULT 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);
}
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class RunningObjectTable method Revoke.
@Override
public HRESULT Revoke(DWORD dwRegister) {
final int vTableId = 4;
WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), dwRegister }, WinNT.HRESULT.class);
return hr;
}
Aggregations