windowfromaccessibleobject returns zero

Hi Everybody,

Please help.

MSAA API windowfromaccessibleobject returns zero. I have no idea why it does this, because I know there is handle to that control(Its checked with various other methods).

[DllImport("oleacc.dll")]
public static extern uint WindowFromAccessibleObject(IAccessible pacc, ref IntPtr phwnd);

Please help.

Regards,
Kavya

[376 byte] By [ASKavya] at [2008-1-10]
# 1
I use following signature and everything works fine:

public static extern int WindowFromAccessibleObject(IAccessible pacc, out IntPtr hwnd);

What is the error code returned from the function if there is one?

MarcoAchtziger at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 2
HI Marco,

Sorry. I could not check the response as I was out of station
Thanks you. I shall try it.
But I feel I have tried this earlier.

for the previous signature, no error code. Handle use to be zero

ASKavya at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 3
HI Marco,

I did check. It doesn't give me any error code. it actually passes the try block.

but handle is zero. Sad

try {
NativeMethods.WindowFromAccessibleObject(accObj, out Handle);
} catch (Exception e) {
Console.WriteLine(e.Message);
}

ASKavya at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 4
You have to store the return value of that method somewhere to obtain the error message. The call does not throw an exception. Maybe you should also set SetLastError=true in your DllImport Statement for WindowFromAccessibleObject so you can additionally check Marshal.GetLastError after the call to that function.
MarcoAchtziger at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 5
HI Marco,

I got actually busy with something. hence couldn't continue!! Sad

Hope to seek your help still

int res= NativeMethods.WindowFromAccessibleObject(accObj, out Handle);
Win32Exception win32 = new Win32Exception(res);
Console.WriteLine(win32.InnerException);
Console.WriteLine(win32.Message);
Console.WriteLine(win32.Source);

I get this error ."An outgoing call cannot be made since the application is dispatching an input-synchronous call" for the above code.

Please help me Sad

ASKavya at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 6
Hi,

I also came across couple of links which says, we can call this in timer event to make it async. Since it is in single thread for me.

Few of the below links

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20152915.html

http://mikedimmick.blogspot.com/2004/02/on-com-pumping-and-clr.html

But, Mine is not a winform app to put timer, So any better suggestion?

Please ehlep

ASKavya at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 7
In what AppartmentState is the thread you are calling WindowFromAccessibleObject from? What does this thread do?
MarcoAchtziger at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 8
Well,

This is sta as of now. I'm not sure if I need to put in different thread

ASKavya at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 9

I had the same problem Here is what I did:

(Windows.Control is my own class not a System.Windows.Forms.Control)

''' <summary>

''' The parent control accociated with the accessibility element

''' </summary>

''' <remarks></remarks>

Private m_Control As Windows.Control

''' <summary>

''' The control that contains this Active Accessibility element

''' </summary>

''' <value></value>

''' <returns></returns>

''' <remarks></remarks>

<TypeConverter(GetType(ExpandableObjectConverter))> _

Public ReadOnly Property Control() As Windows.Control

Get

If m_Control Is Nothing Then

Using r As New Threading.AutoResetEvent(False)

Dim t As New Threading.Thread(AddressOf GetWindow)

t.Start(r)

r.WaitOne()

End Using

End If

Return m_Control

End Get

End Property

''' <summary>

''' Get the window from the accessible object.

''' </summary>

''' <remarks></remarks>

Private Sub GetWindow(ByVal resetevent As Object)

Dim hWnd As IntPtr

WindowFromAccessibleObject(m_Element, hWnd)

m_Control = Windows.Control.Create(hWnd, Nothing, m_Application, 0)

Dim r As Threading.AutoResetEvent = TryCast(resetevent, Threading.AutoResetEvent)

r.Set()

End Sub

GilesBathgate at 2007-10-3 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...

Software Development for Windows Vista

Site Classified