OneNote Interop API targets wrong window instance when multiple

stemarcoh 26 Reputation points
2024-11-23T14:05:09.3+00:00

C# with .NET Framework 4.8, Microsoft® OneNote® 2021 MSO (Version 2410 Build 16.0.18129.20100) 64-bit

Open up two OneNote windows viewing the same page. From the second window, invoke an add-in command that uses the managed Interop API.

Any queries or updates made by the API will target the first OneNote window instance, even while the second window instance is active and has focus.

However, if the content of the page is manually modified from the second [active] window instance, then and only then will the API call target and update the page in the second window.

Expectation is that the updated page content will be visible immediately in the active OneNote window instance.

OneNote
OneNote
A family of Microsoft products that enable users to capture, organize, and reuse notes electronically.
214 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.
11,110 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,063 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Jason Chapman 41 Reputation points
    2024-11-24T13:27:07.9933333+00:00

    A great example of this is when your add-in wants to know "what is the selected text" in the focused, second instance, as the XML request will always give the results from the 1st instance. If you close the first instance or move to another page in the 1st instance, the query will give the correct information.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.