Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 601775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:45:06+00:00 2026-05-13T16:45:06+00:00

i am developing some code in c# where i will be interacting with Microsoft

  • 0

i am developing some code in c# where i will be interacting with Microsoft Word. I want to be able to have the option of re-using an existing instance or as an alternative creating a new instance.

Keeping in mind i want to do all of this using LATE BINDING… it is safe to say i have figured out how to get things working when creating a new instance.. i just call Activator.CreateInstance etc..

The problem i am having is how do i reuse an existing instance, for example, Word is already open and i want to use that instance.

Is there an Activator.UseExistingInstance? or something similar??

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:45:07+00:00Added an answer on May 13, 2026 at 4:45 pm

    You might want to have a look at the AccessibleObjectFromWindow api function defined in Oleacc.dll. Andrew Whitechapel has some articles on how to use it. Based on his articles I wrote an answer to a very similar question (about Excel, not Word), which you can find here:

    How to use use late binding to get Excel instance?

    There you will find an example how to connect to an already running Excel instance and then automating this instance using late binding.

    Update:

    Here is a short sample adapted to Word:

    using System;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    
    namespace WordLateBindingSample
    {
        [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00020400-0000-0000-C000-000000000046")]
        public interface IDispatch
        {
        }
    
        class Program
        {
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            [DllImport("Oleacc.dll")]
            static extern int AccessibleObjectFromWindow(int hwnd, uint dwObjectID, byte[] riid, out IDispatch ptr);
    
            public delegate bool EnumChildCallback(int hwnd, ref int lParam);
    
            [DllImport("User32.dll")]
            public static extern bool EnumChildWindows(int hWndParent, EnumChildCallback lpEnumFunc, ref int lParam);
    
            [DllImport("User32.dll")]
            public static extern int GetClassName(int hWnd, StringBuilder lpClassName, int nMaxCount);
    
            public static bool EnumChildProc(int hwndChild, ref int lParam)
            {
                StringBuilder buf = new StringBuilder(128);
                GetClassName(hwndChild, buf, 128);
                if (buf.ToString() == "_WwG")
                {
                    lParam = hwndChild;
                    return false;
                }
                return true;
            }
    
            static void Main(string[] args)
            {
                // Use the window class name ("OpusApp") to retrieve a handle to Word's main window.
                // Alternatively you can get the window handle via the process id:
                // int hwnd = (int)Process.GetProcessById(wordPid).MainWindowHandle;
                //
                int hwnd = (int)FindWindow("OpusApp", null);
    
                if (hwnd != 0)
                {
                    int hwndChild = 0;
    
                    // Search the accessible child window (it has class name "_WwG") 
                    // as described in http://msdn.microsoft.com/en-us/library/dd317978%28VS.85%29.aspx
                    //
                    EnumChildCallback cb = new EnumChildCallback(EnumChildProc);
                    EnumChildWindows(hwnd, cb, ref hwndChild);
    
                    if (hwndChild != 0)
                    {
                        // We call AccessibleObjectFromWindow, passing the constant OBJID_NATIVEOM (defined in winuser.h) 
                        // and IID_IDispatch - we want an IDispatch pointer into the native object model.
                        //
                        const uint OBJID_NATIVEOM = 0xFFFFFFF0;
                        Guid IID_IDispatch = new Guid("{00020400-0000-0000-C000-000000000046}");
                        IDispatch ptr;
    
                        int hr = AccessibleObjectFromWindow(hwndChild, OBJID_NATIVEOM, IID_IDispatch.ToByteArray(), out ptr);
    
                        if (hr >= 0)
                        {
                            object wordApp = ptr.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, ptr, null);
    
                            object version = wordApp.GetType().InvokeMember("Version", BindingFlags.GetField | BindingFlags.InvokeMethod | BindingFlags.GetProperty, null, wordApp, null);
                            Console.WriteLine(string.Format("Word version is: {0}", version));
                        }
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a application using PHP. Some example code is here. $url =
I am new to developing code in iPhone, and I want to search some
Currently I'm using Visual Studio 2008 (SP1) and developing some code that uses nested
Good evening. I am looking at developing some code that will collect EXIF data
In Visual Studio, I have some Javascript code on a site I'm developing. While
Sometimes for testing/developing purposes we make some changes in the code that must be
I'm currently developing some things in Python and I have a question about variables
I have a project for Linux that i've been developing for some time. Basically
I new in the android developing. I want to develop simple application that will
I'm developing a website for a client, in which they want to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.