Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement StandardAccessble RCW and AccessibleObject CCW #7145

Closed
wants to merge 27 commits into from

Conversation

kant2002
Copy link
Contributor

@kant2002 kant2002 commented May 6, 2022

I realize that EnumVariantWrapper RCW is essentially always implement 3 interfaces which is needed
IEnumVariant, IAccessible and IOleWindow
Some internal things of Win32 prevent me using just single call to CreateStdAccessibleObject
Also add CCW for AccessibleObject

With this change you can run WinForms application with disabled built-in COM except following controls:

  • RichTextBox
  • WebBrowser
  • AxHost

That's important step forward #5163

Microsoft Reviewers: Open in CodeFlow

@kant2002 kant2002 requested a review from a team as a code owner May 6, 2022 06:07
@ghost ghost assigned kant2002 May 6, 2022
@RussKie
Copy link
Member

RussKie commented May 6, 2022

I realize that EnumVariantWrapper RCW is essentially always implement 3 interfaces which is needed
IEnumVariant, IAccessible and IOleWindow
Some internal things of Win32 prevent me using just single call to CreateStdAccessibleObject

Could you please elaborate on what led to the realisation, and what "internal things of Win32" scenarios led to this change? It would be great to capture all of these details, and may be add tests too.

@kant2002
Copy link
Contributor Author

kant2002 commented May 6, 2022

"internal things of Win32" => ComObject which returned from https://docs.microsoft.com/en-us/windows/win32/api/oleacc/nf-oleacc-createstdaccessibleobject#parameters . here declared that parameters can be one of 4 interfaces. IID_IAccessible, IID_IDispatch, IID_IEnumVARIANT, or IID_IUnknown

Then when I probe for supported interfaces in WinFormsComWrappers.CreateObject all objects supports both IAccessible and IEnumVariant. I did try to simplify things, but conversion with ComObject does not work so I abandon that path. I would try to remove duplicate calls to CreateStdAccessibleObject and return back.

@kant2002
Copy link
Contributor Author

kant2002 commented May 6, 2022

Okay. I remove duplicate calls to CreateStdAccessibleObject which just ask for different Com interfaces, so I really do not understand why there was two of them.

Only was to access internal IAccessible which I see is for Non-client area accessible objects. If somebody can tell me more about this scenario in accessibility, and how I can test more in that area?

Otherwise I think this is good.

@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label May 9, 2022
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label May 9, 2022
@kant2002
Copy link
Contributor Author

@RussKie I think I address all questions. Am I?

@kant2002
Copy link
Contributor Author

@RussKie please take a look at this one too.

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'm getting better at this 😄
Is there some way we can verify we're not leaking objects?

@AaronRobinsonMSFT may I get you to review as well, when you have a chance?

RussKie
RussKie previously approved these changes May 16, 2022
kant2002 added a commit to kant2002/winforms that referenced this pull request May 18, 2022
This is successfully catches bug in the dotnet#7145 implementation
@kant2002
Copy link
Contributor Author

Please do not approve. I found test case #7191 which trigger bug with current implementation, and except much more code to make that happens. Overall I hate this AccessibleObject thing.

kant2002 added a commit to kant2002/winforms that referenced this pull request May 18, 2022
This is successfully catches bug in the dotnet#7145 implementation
@kant2002
Copy link
Contributor Author

On latest commit I fix issue and what's important this PR make WinForms finally working without built-in COM.
There some obvious limitations, like Clipboard which I do not finish, and RichTextBox for which I have code, but it's not published yet.

If this PR pass review, it would be time for celebration.

@@ -1749,31 +1749,31 @@ protected void UseStdAccessibleObjects(IntPtr handle)

protected void UseStdAccessibleObjects(IntPtr handle, int objid)
{
object? acc = null;
UnsafeNativeMethods.CreateStdAccessibleObject(
Guid IID_IAccessible = IID.IAccessible;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of this local does not follow conventions, You used iAccessibleId elsewhere. And the same applies to IEnumVariant

DropDownStyle = ComboBoxStyle.DropDown
};
control.CreateControl();
ComboBox.ComboBoxAccessibleObject accessibleObject = new ComboBox.ComboBoxAccessibleObject(control);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider new (control).

@kant2002 kant2002 changed the title Implement StandardAccessble object Implement StandardAccessble RCW and AccessibleObject CCW May 21, 2022
ghost pushed a commit that referenced this pull request May 24, 2022
This is successfully catches bug in the #7145 implementation
I need just call to `GetFocused`, but if some additional check can be made, I can add them.
@kant2002 kant2002 force-pushed the kant/standard-accessible-obect branch from f4e1713 to bfc9519 Compare May 24, 2022 20:16
@kant2002
Copy link
Contributor Author

@RussKie NativeAOT needs you :)

@RussKie
Copy link
Member

RussKie commented May 25, 2022

Apologies, I've been slammed with other work

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 12 to 14
private static extern HRESULT UiaDisconnectProvider(IntPtr provider);
public static HRESULT UiaDisconnectProvider(IRawElementProviderSimple provider)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Missing blank line

((delegate* unmanaged<IntPtr, Oleaut32.VARIANT, IntPtr *, HRESULT>)(*(*(void***)_accessibleInstance + 9)))
(_accessibleInstance, childIdVar, &value).ThrowIfFailed();
return value == IntPtr.Zero ? null : Marshal.GetObjectForIUnknown(value);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm I understand this correctly - when the return object will be GC'ed, value will get released. Is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. From what I understand Marshal.GetObjectForIUnknown creates same RCW as built-in COM interop.

@RussKie
Copy link
Member

RussKie commented May 25, 2022

@AaronRobinsonMSFT if you could spare few minutes for another pass, it'd be great. Mainly to see if we're leaking anything.

@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label May 25, 2022
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label May 25, 2022
kant2002 added 3 commits July 5, 2022 12:48
Because I provide AccessibleObject via WM_OBJECT I have to provide 3 interfaces
IAccessible, IDispatch and IEnumVariant.
But we rely on the IOleWindowVtbl
Also I discover incorrect memory definition in ILegacyIAccessibleProvider
@RussKie
Copy link
Member

RussKie commented Jul 18, 2022

I've just got back from being OOF, and looks like you've wrestled the tests over. I'm a bit swamped atm, but I'll try to get this reviewed by the EOW.

@RussKie
Copy link
Member

RussKie commented Jul 18, 2022

@Olina-Zhang can you please schedule a test run for this change?

@RussKie RussKie added waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) waiting-review This item is waiting on review by one or more members of team labels Jul 18, 2022
@Olina-Zhang
Copy link
Member

@Olina-Zhang can you please schedule a test run for this change?

@kant2002 @RussKie I quickly tested the updated change, still have issue in here:

  1. Our automation cases hit the issue about missing DoDragDrop test method, it seems your PR is not based on the latest main after the PR: Add support for drag images and drop descriptions #6576 merged
  2. Picked up comboBox control to test in Accessibility tools: Accessibiltiy Insight, Inspect and Narrator, these tools cannot focus on or announce child elements automatically.

AccessibilityInsight result in this PR change:
AccessibilityInsight
Inspect result in this PR change: UIA tree cannot updated automatically, this effects Narrator announcement behavior.
Inspect

@kant2002
Copy link
Contributor Author

Thanks! Will take a look and rebase on latest main

@RussKie RussKie added waiting-author-feedback The team requires more information from the author and removed waiting-for-testing The PR is awaiting manual testing by the primary team; no action is yet required from the author(s) waiting-review This item is waiting on review by one or more members of team labels Jul 19, 2022
@ghost ghost added the no-recent-activity label Nov 16, 2022
@ghost
Copy link

ghost commented Nov 16, 2022

This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.

It will be closed if no further activity occurs within 7 days of this comment.

@dreddy-work
Copy link
Member

prevent bot from closing it.

@ghost ghost removed the no-recent-activity label Nov 23, 2022
@ghost ghost added the no-recent-activity label Dec 7, 2022
@ghost
Copy link

ghost commented Dec 7, 2022

This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.

It will be closed if no further activity occurs within 7 days of this comment.

@dreddy-work
Copy link
Member

ping.

@ghost ghost removed the no-recent-activity label Jun 5, 2023
@ghost ghost added the no-recent-activity label Jun 19, 2023
@ghost
Copy link

ghost commented Jun 19, 2023

This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.

It will be closed if no further activity occurs within 7 days of this comment.

@JeremyKuhne
Copy link
Member

Thanks for the effort here @kant2002- it helped get us in gear to make the COM changes we already made for .NET 8. @lonitra is handling AccessibleObject with CsWin32 and ComWrappers in .NET 9.

@JeremyKuhne JeremyKuhne closed this Oct 4, 2023
@ghost ghost removed no-recent-activity waiting-author-feedback The team requires more information from the author labels Oct 4, 2023
@kant2002
Copy link
Contributor Author

kant2002 commented Oct 4, 2023

I love this news :)

@ghost ghost locked as resolved and limited conversation to collaborators Nov 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants