Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Late binding in C# to Word Control in XAML/Store app

Previously I've been able to find a Word document inside another application using

[DllImport("Oleacc.dll")]
private static extern long AccessibleObjectFromWindow(int windowHandle, int objectID, Guid refID, ref IntPtr accessibleObject);

and casting the resultant object returned into a

Microsoft.Office.Interop.Word.Window

This works pretty well in that I can inspect different properties about Word within, say, Microsoft Outlook, as MS Outlook uses a Word Window to render its email content.

However, its a little trickier in XAML/Windows Store app, as it appears that the Word doc is embedded without a direct window handle. Below is the inspector.exe output of the Window. The selected 'Message' item is my Word instance. However the only items in the tree with NativeWindowHandles according to the accessibility inspector are the Mail window and the title window.

Does anyone know how to marshall that Word control in an external XAML/store app into a C# object?

enter image description here

like image 502
Richthofen Avatar asked Jul 14 '16 20:07

Richthofen


People also ask

What is early binding and late binding in C?

If the compiler knows at the compile-time which function is called, it is called early binding. If a compiler does not know at compile-time which functions to call up until the run-time, it is called late binding.

What is late binding with example?

Basically, late binding is achieved by using virtual methods. The performance of late binding is slower than early binding because it requires lookups at run-time. Example: In the below, program the obj holds integer type data and obj1 holds double type data. But the compiler doesn't resolve these at compile-time.

Why do we use late binding?

Late binding is generally used in scenarios where an exact object interface is unknown at design time, or where interaction with multiple unknown servers invoke functions by names. It is also used as a workaround for compatibility issues between multiple versions of an improperly modified component.

What is binding in C?

The binding means the process of converting identifiers into addresses. For each variables and functions this binding is done. For functions it is matching the call with the right function definition by the compiler. The binding is done either at compile time or at runtime.


1 Answers

You're out of luck here. What you see here in the Inpect tool is indeed an element which has a "_WwG" class name, but you are not dealing with an automatable instance of Word here.

What is missing here is first of all a native window handle of class "_WwG", and moreover, the code that is used - although being a Microsoft Office 2016 component - does not expose any COM interface that you can access (at least not the familiar COM object model of Word).

Depending on your requirements, you may be able to find a solution based on UI automation - the same kind of inspection technique that is used by the Inspect tool.

like image 131
Dirk Vollmar Avatar answered Oct 05 '22 18:10

Dirk Vollmar