Are custom UIAutomation patterns impossible in c#?

Chris Shearer Cooper 1 Reputation point
2022-06-15T22:27:54.977+00:00

I'm trying to create a custom pattern for UIAutomation, and it's been quite the hassle.
It seems that it's impossible to call IUIAutomationRegistrar.RegisterPattern() from c# (see this question), I got around that by calling RegisterPattern() from a c++ DLL that I linked in. I'm now doing that from both my automated UI test harness and my main application, and in both cases RegisterPattern() is succeeding (returning S_OK) and telling me that the patternID is 50000. So far so good!
But in my test harness, if I call IUIAutomationElement.GetCurrentPattern(50000), it returns a null pointer. I put extra logging into my main application, and it sure looks like the test harness isn't even trying to contact the application about this. I'm logging when the main app gets WM_GETOBJECT, and I don't see anything there that would indicate that's happening.
Is support for UIAutomation under c# extremely limited? No way to do custom patterns?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
725 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,248 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,726 Reputation points
    2022-06-16T20:42:38+00:00

    I converted the MS C++ sample from Register custom properties, events, and control patterns
    and it seems to work : RegisterPattern returns S_OK and returned values and arrays are filled
    Link, as I cannot post code (bugged forums...) =>

    IAutomationRegistrar.RegisterPattern in C#, tested on Windows 10 21H1, compiled witn "Any CPU"

    0 comments No comments