How can I "fix" a mis-imported COM interface (c#/WPF)?

Chris Shearer Cooper 1 Reputation point
2022-06-14T14:59:14.647+00:00

I want to add a custom pattern for UIAutomation, but I can't get the IUIAutomationRegistrar.RegisterPattern() method to work. I suspect part of the problem is that the method gets imported into c# like this:

void RegisterPattern([In] ref UIAutomationPatternInfo pattern,  
   out int pPatternId, out int pPatternAvailablePropertyId,  
   [In] uint propertyIdCount, out int pPropertyIds,  
   [In] uint eventIdCount, out int pEventIds);  

but the interface in C/C++ looks like this:

HRESULT RegisterPattern(  
  [in]  const UIAutomationPatternInfo *pattern,  
  [out] PATTERNID                     *pPatternId,  
  [out] PROPERTYID                    *pPatternAvailablePropertyId,  
  [in]  UINT                          propertyIdCount,  
  [out] PROPERTYID                    *pPropertyIds,  
  [in]  UINT                          eventIdCount,  
  [out] EVENTID                       *pEventIds  
);  

So the importer mistakenly assumed that "[out] PROPERTYID *pPropertyIds" was a reference to a single PROPERTYID (int) instead of a pointer to an array.

Is there a way to tell the importer how to do this right?

By the way, I started my question on StackOverflow, for more details than you really wanted:
https://stackoverflow.com/questions/72578187/how-add-pattern-and-or-property-to-uiautomation-c
https://stackoverflow.com/questions/72607121/are-there-updated-uiautomation-dlls-creating-custom-pattern-in-c

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,430 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,315 questions
{count} votes