Any way to avoid creating a huge c # COM interface shell when only a few methods are required?

Greetings to all

Im working on a C # program that requires to get the hot item index in Windows 7 Explorers new ItemsView control. Fortunately, Microsoft provided a way to do this through UI Automation by requesting custom properties for the control.

Unfortunately, the System.Windows.Automation namespace is inexplicable, it seems to make it impossible to request custom properties! This leaves me with an undesirable position to completely push through the C # Automation namespace and use only the unmanaged version of COM. One way to do this is to put all the automation code in a separate C ++ / CLI module and call it from my C # application. However, I would like to avoid this option, if possible, as it adds more files to my project, and Id should worry about 32/64-bit issues, etc.

Another option is to use the ComImport attribute to declare the corresponding interfaces and do everything through COM-interop. This is what I would like to do. However, the corresponding interfaces, such as IUIAutomation and IUIAutomationElement, are FREAKING HUGE. They have hundreds of methods in general, as well as links to tons and tons of interfaces (which I suppose I should also declare), almost all of which I will never use. I do not think that UI automation interfaces are declared in any type library, so I cannot use TLBIMP.

, bajillion # , ? , # 4.0 "" , COM; , ?

+3
1

( COM- #) , . , , ( !). .. ,

[ComImport, Guid("30cbe57d-d9d0-452a-ab13-7ac5ac4825ee"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IUIAutomation
{
    void CompareElements();
    void CompareRuntimeIds();
    void GetRootElement();
    // 50 or so other methods...
    // ... define only the signatures for the ones you actually need
}

, UIAutomationClient.h( SDK Windows).

+7

Source: https://habr.com/ru/post/1745537/


All Articles