I have been using MSAA through C++/CLI to interact with a windows forms UI component (it is an Infragistics UltraWinTree). The code to do so is very straightforward:
IAccessible* accessibleObj; AccessibleObjectFromWindow(hwnd, OBJID_CLIENT, IID_IAccessible, (void**)&accessibleObj); long childCount; accessibleObj->get_accChildCount(&childCount);
The extremely odd issue with this code is that if I compile the code with /clr to create a managed executable childCount is 21 (the correct answer) while on the other hand if there is no /clr specified the unmanaged executable has childCount as 0 (incorrect). It is extremely odd that this would be happening, especially since the managed version just makes an unmanaged call to AccessibleObjectFromWindow anyway.
From debugging I found that although the HRESULT from AccessibleObjectFromWindow is S_OK in both cases in the failing case GetLastError returns 2 (which for general system errors is "File Not Found") while for the working version it returns 0. Also I tried sending WM_GetObject directly to the Hwnd and found that it returned a non-zero value in both cases. Lastly I compared a procmon registry and file system capture for both cases and found that the failing case only checks the registry key for IAccessible while the succeeding case does tons more stuff checking lots of other registry keys (not sure why).
So I am not sure if this is due to a security issue or a difference in how the managed vs unmanaged version located files, but any way that I can look at it now it seems like it has something to do with finer details of MSAA that I am not aware of. Any help will be greatly appreciated :).