Ejemplo n.º 1
0
            private Microsoft.Office.Interop.Excel.Application SearchExcelInterop(Process p)
            {
                Microsoft.Office.Interop.Excel.Window ptr = null;
                int hwnd = 0;

                int hWndParent = (int)p.MainWindowHandle;

                if (hWndParent == 0)
                {
                    throw new ExcelMainWindowNotFoundException();
                }

                EnumChildWindows(hWndParent, EnumChildFunc, ref hwnd);
                if (hwnd == 0)
                {
                    throw new ExcelChildWindowNotFoundException();
                }

                int hr = AccessibleObjectFromWindow(hwnd, DW_OBJECTID, rrid.ToByteArray(), ref ptr);

                if (hr < 0)
                {
                    throw new AccessibleObjectNotFoundException();
                }
                return(ptr.Application);
            }
 public static extern int AccessibleObjectFromWindow(
     int hwnd, uint dwObjectID, byte[] riid,
     ref Microsoft.Office.Interop.Excel.Window ptr);