Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / April 2006

Tip: Looking for answers? Try searching our database.

E_FAIL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
danjones.email@gmail.com - 20 Apr 2006 20:29 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.