using System;
using System.Windows.Automation;
using System.Windows.Forms;
namespace Sandbox083116
{
public partial class Form1 : Form
{
private AutomationElement formAutomationElement;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
formAutomationElement = AutomationElement.FromHandle(Handle);
}
}
}
I've saw a few posts about just ignoring first time exceptions if they are handled inside the windows dll's etc...
using System;
using System.Windows.Automation;
using System.Windows.Forms;
namespace Sandbox083116
{
public partial class Form1 : Form
{
private AutomationElement formAutomationElement;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
formAutomationElement = AutomationElement.FromHandle(Handle);
}
}
}
I have saw posts saying to ignore first time exceptions that are handled in windows .DLL files. I was just curious if there is some method or additional information you could pass in this call to eliminate the exception? I've tried my best to
debug it, and got deep into the .NET Framework but, cannot step into the OLEACC.DLL file, well the assembly but that didn't help much. It calls a function at some address....that the ends up handling the exception.
//The call stack before the exception looks like this... First we are down to the fallback proxy...(ProxyManager.cs Line 554)
// use the fallback proxy if there is one
if (proxy == null)
{
proxy = FindProxyInEntryOrArrayList(ProxyScoping.FallbackHandlers, _fallbackHandlers, ref imageName, hwnd, idChild, idObject, null);
}
//ProxyManager.cs (Line 630) in this case we have a count of 1, so it will only iterate through 1 time.
// this is a for loop because we need this to be thread safe and ClientSideProviderFactoryCallback calls out
// so there would have been a lock in force when the call out was made which causes
// deadlock. We need to make our locks as narrow as possible.
for( int i = 0; i < count; i++ )
{
object entry;
lock (_lockObj)
{
entry = array[i];
}
proxy = GetProxyFromEntry(findType, entry, ref imageName, hwnd, idChild, idObject, classNameForPartialMatch);
if( proxy != null )
break;
}
return proxy;
}
//ProxyManager.cs (Line 714)
// if we get an exception creating a proxy just don't create the proxy and let the UIAutomation default proxy be used
// This will still allow the tree to be navigated and some properties to be made availible.
//
try
{
return factoryCallback(hwnd, idChild, idObject);
}
//MsaaNativeProvider.cs Line 105
Accessible acc = Accessible.CreateNativeFromEvent(hwnd, idObject, idChild);
//Accessible (Line 127) (inside the Try/Catch)
internal static Accessible CreateNativeFromEvent(IntPtr hwnd, int idObject, int idChild)
{
IntPtr zero = IntPtr.Zero;
if (Environment.OSVersion.Version.Major >= 6)
{
zero = new IntPtr((long) MS.Win32.UnsafeNativeMethods.GetCurrentProcessId());
}
IntPtr lResult = Misc.ProxySendMessage(hwnd, 0x3d, zero, new IntPtr(idObject));
if (lResult != IntPtr.Zero)
{
Accessibility.IAccessible ppvObject = null;
int num = 1;
try
{
num = MS.Win32.UnsafeNativeMethods.ObjectFromLresult(lResult, ref MS.Win32.UnsafeNativeMethods.IID_IAccessible, zero, ref ppvObject);
}
The last call to ObjectFromLresult, is a low level non-managed win32 call. I cannot step into, I was unable to find any source code for I do have the symbols and I can stumble through assembly but, wasn't able to really pinpoint anything I could do
different.
This call is being made to help bring up a keyboard inside windows 10 when you click on a text box. It is from a post: https://social.msdn.microsoft.com/Forums/silverlight/en-US/705c7ffc-f137-4e98-905c-8b3e8ba058ec/windows-10-tablet-mode-why-doesnt-winforms-textbox-show-the-onscreen-keyboard-if-getting-the?forum=winforms
A deeper dive from that post will find that https://social.msdn.microsoft.com/profile/dmitry%20lyalin%20(msft)/ came
up with it, He claims
This is NOT
a formal sample from the Windows or WPF Product Team, I’m merely
a fan of WPF and wanted to get this code sample out to our community
- While this is NOT a formal sample from Microsoft, at the same time it doesn’t use any hidden or unsupported API's, so developers that do their own research and testing can use this type of approach in their applications.
Remember, this is just a sample!
This is his code that was converted
// Enables WPF to mark edit field as supporting text pattern (Automation Concept)
System.Windows.Automation.AutomationElement asForm =
System.Windows.Automation.AutomationElement.FromHandle(new WindowInteropHelper(this).Handle);
Brian Lagunas also has a different solution on http://brianlagunas.com/showing-windows-8-touch-keyboard-wpf/
Does anyone know a better solution? Does anyone know how to avoid the exception?