use of com.sun.jna.platform.win32.WinNT.HRESULT 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.WinNT.HRESULT 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.WinNT.HRESULT in project jna by java-native-access.
the class COMBindingBaseObject method oleMethod.
protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, IDispatch pDisp, DISPID dispId, VARIANT[] pArgs) throws COMException {
if (pDisp == null)
throw new COMException("pDisp (IDispatch) parameter is null!");
// variable declaration
int _argsLen = 0;
VARIANT[] _args = null;
DISPPARAMS.ByReference dp = new DISPPARAMS.ByReference();
EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference();
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 });
}
// Build DISPPARAMS
if (_argsLen > 0) {
dp.setArgs(_args);
// write 'DISPPARAMS' structure to memory
dp.write();
}
// 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;
}
// Make the call!
HRESULT hr = pDisp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, 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 EnumMoniker method Reset.
@Override
public HRESULT Reset() {
final int vTableId = 5;
WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer() }, WinNT.HRESULT.class);
return hr;
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class RunningObjectTable method GetObject.
@Override
public HRESULT GetObject(Pointer pmkObjectName, PointerByReference ppunkObject) {
final int vTableId = 6;
WinNT.HRESULT hr = (WinNT.HRESULT) this._invokeNativeObject(vTableId, new Object[] { this.getPointer(), pmkObjectName, ppunkObject }, WinNT.HRESULT.class);
return hr;
}
Aggregations