Hi all,

I've been trying to marshal AccessibileObjectFromWindow without luck. The code compiles but I get an exception at the line Marshal.Queryinterface which reads "System.NullReferenceException, Object reference not set to an instance of an object". What did I do wrong?


private static extern long AccessibleObjectFromWindow(int windowHandle, int objectID, Guid refID, ref IntPtr accessibleObject);

//winable.h constants
private int OBJID_WINDOW = 0x0;

public void GetWindow(int handleWindow)

IAccessible iDialogWindow = null;

//Guid obtained from OleAcc.idl from Platform SDK
Guid iAccessibleGuid = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");
IntPtr dialogWindow = Marshal.AllocCoTaskMem(4);
IntPtr dialogWindowp = Marshal.AllocCoTaskMem(4);
Marshal.StructureToPtr(dialogWindow, dialogWindowp, false);

AccessibleObjectFromWindow(handleWindow, OBJID_WINDOW, iAccessibleGuid , ref dialogWindowp);

dialogWindow = Marshal.ReadIntPtr(dialogWindowp);

IntPtr iAccessiblePtr = IntPtr.Zero;
Marshal.QueryInterface(dialogWindow, ref iAccessibleGuid, out iAccessiblePtr);