Not sure if this is the modern, recommended way either but here are the editted highlights. I have partial success.
* I looked at the examples posted on here for COM Mapping of ITaskbarList3
* Create a handler that descends from Unknown.
public static UIAutomationHandler create() {
Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_APARTMENTTHREADED);
PointerByReference pbr = new PointerByReference();
WinNT.HRESULT hr = Ole32.INSTANCE.CoCreateInstance(
CLSID_CUIAutomation,
null,
WTypes.CLSCTX_SERVER,
IID_IUIAutomation,
pbr);
COMUtils.checkRC(hr);
UIAutomationHandler tb = new UIAutomationHandler(pbr.getValue());
return tb;
}
* I can then write wrappers around each of the COM methods (for example)
public void GetRootElement(PointerByReference elt) {
int result = this._invokeNativeInt(5, new Object[]{this.getPointer(), elt});
COMUtils.checkRC(new WinNT.HRESULT(result));
}
* I can see that this works as I have also written wrappers for IAutomationElement, and can get the name and classname of the root element itself.
However, when I try to create a property condition (IUIAutomationAndCondition), which requires 2 other property conditions, then I get an Invalid memory exception.
My call to CreateAndCondition looks like this..
(basic is takes 2 conditions and gives you back a condition based on them)
public void CreateAndCondition(PointerByReference condition0, PointerByReference condition1, PointerByReference condition) {
int result = this._invokeNativeInt(25, new Object[]{this.getPointer(), condition0, condition1, condition});
COMUtils.checkRC(new WinNT.HRESULT(result));
}
I suspect that it is something I need to do when I create the input Conditions (wrapper looks like this).
public void CreatePropertyCondition(int propertyId, Variant.VARIANT value, PointerByReference elt) {
int result = this._invokeNativeInt(23, new Object[]{this.getPointer(), propertyId, value, elt});
COMUtils.checkRC(new WinNT.HRESULT(result));
}
Thanks, your examples don't look too much different from mine.
Mark H