I am trying to use AccessibleObjectFromWindow() and it keeps returning
E_FAIL. This seems to be an ambiguous error message and i feel like i
have tried everything. I used Spy++ to verify that i am giving it the
correct handle and several sources have told me that I do have the
correct dwObjectID and Guid (although i am still willing to try any
suggestions at this point.) I did read somewhere that it might not be
able to find accessibleObjects from visual studio so i tried running my
code from the .exe and that didn't seem to make a difference. Below is
the code i am using. If anyone has any ideas on where to look or has
seen similar problems i would appreciate any help.
long dwObjectID = OBJID_CLIENT;
IntPtr objIDPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(long)));
Guid refID = new Guid("618736E0-3C3D-11CF-810C-00AA00389B71");
//IAccessable
IntPtr theObject =
Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(GUID)));
IntPtr TheObjectPtr =
Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr)));
Marshal.StructureToPtr(theObject, TheObjectPtr, false);
int ret = AccessibleObjectFromWindow(hwnd, objIDPtr, ref refID, ref
TheObjectPtr);
Thanks,
Dan
Mattias Sjögren - 21 Apr 2006 06:29 GMT
Dan,
You're complicating things more than necessary. With a declaration
like this
[DllImport("oleacc.dll")]
static exstern int AccessibleObjectFromWindow(IntPtr hwnd, uint
dwObjectID, ref Guid riid, out IntPtr ppvObject);
you can simply call it like this
IntPtr TheObjectPtr;
int ret = AccessibleObjectFromWindow(hwnd, OBJID_CLIENT, ref refID,
ref TheObjectPtr);
No need for any Marshal.Alloc calls.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
danjones.email@gmail.com - 21 Apr 2006 15:19 GMT
If I don't allocate space for the object that is to be set in
TheObjectPtr, then it will give me the exception "Object reference not
set to an instance of an object" when AccessibleObjectFromWindow is
called. But moving OBJID_CLIENT into the function call does simplify
the problem.