title: AccessibleObjectFromWindow returns an E_FAIL code
body: <p>Please review the following code, which is supposed to connect to Excel currently running:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;oleacc.h&gt;
  #import "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\MSO.DLL" no_implementation rename("RGB", "ExclRGB") rename("DocumentProperties", "ExclDocumentProperties") rename("SearchPath", "ExclSearchPath")
  #import "C:\Program Files (x86)\Common Files\microsoft shared\VBA\VBA6\VBE6EXT.OLB" no_implementation
  #import "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE" rename("DialogBox", "ExclDialogBox") rename("RGB", "ExclRGB") rename("CopyFile", "ExclCopyFile") rename("ReplaceText", "ExclReplaceText")
  
  BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM)
  {
     WCHAR szClassName[64];
     if(GetClassNameW(hwnd, szClassName, 64))
     {
        if(_wcsicmp(szClassName, L"EXCEL7") == 0)
        {
           //Get AccessibleObject
           Excel::Window* pWindow = NULL;
           HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Excel::Window), (void**)&amp;pWindow);
           if(hr == S_OK)
           {
              //Excel object is now in pWindow pointer, from this you can obtain the document or application
              Excel::_Application* pApp = NULL;
              pApp = pWindow-&gt;GetApplication();
              pWindow-&gt;Release();
           }
           return false;     // Stops enumerating through children
        }
     }
     return true;
  }
  
  int main( int argc, CHAR* argv[])
  {
      //The main window in Microsoft Excel has a class name of XLMAIN
      HWND excelWindow = FindWindow(L"XLMAIN", NULL);
      //Use the EnumChildWindows function to iterate through all child windows until we find _WwG
      EnumChildWindows(excelWindow, (WNDENUMPROC) EnumChildProc, (LPARAM)1);
      return 0;
  }
  </code></pre>
  
  <p>The truth is Excel really running in current moment, but AccessibleObjectFromWindow returns E_FAIL.
  I also tried to run this code in a loop and switch to Excel to it focused application. The same story, AccessibleObjectFromWindow returns an E_FAIL.
  I am now searching in the internet for an answer but all found before gave me nothing. So if someone could provide an explanation it would be greatly appreciated.</p>