I'm playing around with these two native win32 functions:
[DllImport( "oleacc.dll" )]
public static extern int AccessibleObjectFromWindow(
IntPtr hwnd,
int dwObjectID,
ref Guid refID,
ref Accessibility.IAccessible ppvObject );
[DllImport( "oleacc.dll" )]
public static extern uint AccessibleChildren(
Accessibility.IAccessible paccContainer,
int iChildStart,
int cChildren,
[Out] object[] rgvarChildren,
out int pcObtained );
And I'm having a hard time figuring out if I should/need to call Marshal.ReleaseComObject on any of the returned objects. I would be thankful is someone could enlighten me on this topic! Here's a sample usage:
Accessibility.IAccessible test(
int hWnd,
string accessName )
{
Guid guidCOM = new Guid( 0x618736E0, 0x3C3D, 0x11CF, 0x81, 0xC, 0x0, 0xAA, 0x0, 0x38, 0x9B, 0x71 );
Accessibility.IAccessible a = null;
AccessibleObjectFromWindow(
new IntPtr( hWnd ),
-4,
ref guidCOM,
ref a );
object[] children = new object[a.accChildCount];
int z;
AccessibleChildren( a, 0, children.Length, children, out z );
foreach ( Accessibility.IAccessible a2 in children )
try
{
if ( a2.get_accName( 0 ) == accessName )
return a2;
}
catch
{
}
return null;
}