I use iServiceProvider.QueryService to call get IAccessibleEx, but it return -2147024809

71 views
Skip to first unread message

Hank Huang

unread,
Sep 1, 2021, 8:18:26 AM9/1/21
to Java Native Access
public class IServiceProvider extends COMInvoker {
public IServiceProvider() {
}

public IServiceProvider(Pointer pvInstance) {
this.setPointer(pvInstance);
}

public WinNT.HRESULT QueryInterface(Guid.REFIID var1, PointerByReference var2) {
return (WinNT.HRESULT)this._invokeNativeObject(0, new Object[]{this.getPointer(), var1,var2}, WinNT.HRESULT.class);

}

public int AddRef() {
return (int) this._invokeNativeObject(1, new Object[]{this.getPointer()}, WinNT.HRESULT.class);
}

public int Release() {
return (int) this._invokeNativeObject(2, new Object[]{this.getPointer()}, WinNT.HRESULT.class);
}

public WinNT.HRESULT QueryService(Guid.REFIID var1, Guid.REFIID var2, PointerByReference var3) {
return (WinNT.HRESULT)this._invokeNativeObject(3, new Object[]{this.getPointer(), var1, var2,var3}, WinNT.HRESULT.class);
}
}

String appLaunchPath = "C:\\Windows\\WinSxS\\wow64_microsoft-windows-calc_31bf3856ad364e35_10.0.19041.1_none_6a03b910ee7a4073\\calc.exe";
CallKernel32.launchApp(appLaunchPath);
WinDef.HWND currentWinHWND = User32.INSTANCE.GetForegroundWindow();
CallOleacc.getAccessibleObject(currentWinHWND);
// First, get IServiceProvider from the IAccessible.
PointerByReference pSp = new PointerByReference();
IID IID_IServiceProvider = new IID("{6D5140C1-7436-11CE-8034-00AA006009FA}");
REFIID REFIID_IServiceProvider = new REFIID(IID_IServiceProvider);
hr = CallOleacc.getAccessibleObject(currentWinHWND).QueryInterface(REFIID_IServiceProvider, pSp);
if (!COMUtils.FAILED(hr)) {
System.out.println(hr);
System.out.println("successful");
}
ServiceProvider iServiceProvider = new ServiceProvider(pSp.getValue());
PointerByReference paex = new PointerByReference();
GUID IID_IAccessibleEx = new GUID("{F8b80AdA-2C44-48D0-89BE-5FF23C9CD875}");
REFIID REFIID_IAccessibleEx = new REFIID(IID_IAccessibleEx.getPointer());
hr = iServiceProvider.QueryService(REFIID_IAccessibleEx,REFIID_IAccessibleEx,paex);
if (!COMUtils.FAILED(hr)) {
System.out.println("successful");
}else {
System.out.println(hr);
System.out.println("failed");
}
}


it return 

0
successful
failed

Hank Huang

unread,
Sep 1, 2021, 10:00:50 AM9/1/21
to Java Native Access

Daniel B. Widdis

unread,
Sep 1, 2021, 12:32:51 PM9/1/21
to Java Native Access
The error code from the call to QueryService is "Invalid Argument" so it points to a potential issue with use of this mapping:

public WinNT.HRESULT QueryService(Guid.REFIID var1, Guid.REFIID var2, PointerByReference var3) {
    return (WinNT.HRESULT)this._invokeNativeObject(3, new Object[]{this.getPointer(), var1, var2,var3}, WinNT.HRESULT.class);
}


But in your code where it is failing you are only calling it with two arguments:

hr = iServiceProvider.QueryService(REFIID_IAccessibleEx,REFIID_IAccessibleEx,paex);

So where is the two-argument implementation?

As an aside, you should have your IServiceProvider class extend Unknown, which gets you those first three mappings and avoids duplication.

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/ded199b5-a20c-49a8-92eb-f930b7ddca51n%40googlegroups.com.


--
Dan Widdis

Daniel B. Widdis

unread,
Sep 1, 2021, 12:34:36 PM9/1/21
to Java Native Access
Actually I see the two-arg implementation now, sorry.  But the first argument is a "this" pointer to the guidService, so your mapping of var1 to Guid.REFIID is wrong.

Matthias Bläsing

unread,
Sep 1, 2021, 4:33:04 PM9/1/21
to jna-...@googlegroups.com
Hi,

Am Mittwoch, dem 01.09.2021 um 05:18 -0700 schrieb 'Hank Huang' via Java Native Access:
> [Inline Code]

you want help, please at least make it easy to help you. The code you
provided is not runnable, so it does not really help. Please:

1. Create a repository on a public code hosting system
(github the most obvious)
2. Create a simple project structure - with a common build system 
(I suggest maven)
3. Ensure that all needed code is in the repository

That way, we can focus on fixing the problem and not guessing where
your sample is missing things.

Thank you

Matthias


Hank Huang

unread,
Sep 1, 2021, 8:19:56 PM9/1/21
to Java Native Access

Hank Huang

unread,
Sep 1, 2021, 8:26:42 PM9/1/21
to Java Native Access
I don’t know how to get the pointer to the guidService. I saw that the official website says the type of REFGUID is needed, but I can’t find the corresponding one in JNA.

Hank Huang

unread,
Sep 1, 2021, 9:04:32 PM9/1/21
to Java Native Access
GUID GUID_IAccessibleEx = new GUID("f8b80ada-2c44-48d0-89be-5ff23c9cd875");

hr = iServiceProvider.QueryService(GUID_IAccessibleEx.getPointer(),GUID_IAccessibleEx.getPointer(),paex);

I tried to write like this, but it still returns -2147024809

Daniel Widdis

unread,
Sep 1, 2021, 11:10:35 PM9/1/21
to Java Native Access
REFGUID is a pointer to a GUID.  So GUID.ByReference would be the equivalent, but passing the pointer as you've just said you've done (assuming you mapped the COM interface to match) should have worked.

What I don't understand reading the docs is that one parameter is a REFGUID and one's a REFIID, so I don't see how/why the same ID is passed as both parameters.

Hank Huang

unread,
Sep 1, 2021, 11:16:56 PM9/1/21
to jna-...@googlegroups.com
I also don’t understand why I have to pass two identical values , and I give two point of GUID, it still returns parameter error

Hank Huang

unread,
Sep 1, 2021, 11:27:12 PM9/1/21
to Java Native Access
https://github.com/letmeNo1/Test  

I have submitted my code on github,  Could you help me take a look if you can

Daniel Widdis

unread,
Sep 2, 2021, 12:02:43 AM9/2/21
to jna-...@googlegroups.com

I’ve looked. Spent about an hour on it before my last reply.

 

I don’t know why it doesn’t work, but I am very suspicious of the two identical ID parameters.  Are there any other examples of this working, other than the one you cited?

--
You received this message because you are subscribed to a topic in the Google Groups "Java Native Access" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jna-users/wucthsFIVoc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/57e7bc1d-25f6-4872-911a-581adff81c50n%40googlegroups.com.

Hank Huang

unread,
Sep 2, 2021, 12:10:42 AM9/2/21
to jna-...@googlegroups.com
https://docs.microsoft.com/en-us/windows/win32/winauto/using-iaccessibleex-from-a-client



*** IServiceProvider methods ***/
HRESULT (STDMETHODCALLTYPE *QueryService)(
IServiceProvider* This,
REFGUID guidService,
REFIID riid,
void **ppvObject);




2021年9月1日 下午10:00,'Hank Huang' via Java Native Access <jna-...@googlegroups.com> 写道:

[EXTERNAL]

-- 
You received this message because you are subscribed to a topic in the Google Groups "Java Native Access" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jna-users/wucthsFIVoc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jna-users+...@googlegroups.com.

Daniel Widdis

unread,
Sep 2, 2021, 1:14:38 AM9/2/21
to jna-...@googlegroups.com

When you pass just the pointers (the .getPointer() version below), I think you may need to explicitly write the Java-side code values to native memory.  Try GUID_IAccessibleEx.write(); before the below call.

 

You wouldn’t have to do this if you passed the GUID.ByReference, as it would autowrite.

--

You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.

Hank Huang

unread,
Sep 2, 2021, 1:24:56 AM9/2/21
to jna-...@googlegroups.com
Unfortunately, this still returns a parameter error

2021年9月2日 下午1:14,Daniel Widdis <wid...@gmail.com> 写道:

[EXTERNAL]

Hank Huang

unread,
Sep 2, 2021, 5:32:12 AM9/2/21
to Java Native Access

I also tried this method, but the result is also returned 2147024809. The result is too desperate, but I will continue to try, if there is a result, I will sync here

GUID.ByReference lpiid = new GUID.ByReference();
WinNT.HRESULT h2 = Ole32.INSTANCE.IIDFromString(
"{F8b80ADA-2C44-48D0-89BE-5FF23C9CD875}", lpiid);
System.out.println(h2);
System.out.println(lpiid);
hr = iServiceProvider.QueryService(lpiid,lpiid,paex);

Matthias Bläsing

unread,
Sep 2, 2021, 3:53:56 PM9/2/21
to jna-...@googlegroups.com
Hi,

Am Mittwoch, dem 01.09.2021 um 17:19 -0700 schrieb 'Hank Huang' via Java Native Access:
> https://github.com/letmeNo1/Test my code addresss

thank you. However I did not find anything obviously wrong. At this
point I don't understand why it does not work.

Greetings

Matthias

hank huang

unread,
Aug 3, 2022, 10:05:36 PM8/3/22
to Java Native Access

Happily, I finally found the cause of the problem. The reason is that the element object at the root node does not support Get IAccessibleEX. Just filter out the root node and call the method from the level below it
Reply all
Reply to author
Forward
0 new messages