tags:

views:

200

answers:

1

I'm trying to do a few internet explorer automation tasks and it's requiring me to use IViewObject. What is IViewObject? Where can I find it's definition?

I've been google-ing and everything I find has a different interface definition for IViewObject. Different methods or different parameters going into the same methods.

How do I know what interface definition to use with internet explorer?

This is one definition I found on pinvoke.net

[GuidAttribute( "0000010d-0000-0000-C000-000000000046" )]
[InterfaceTypeAttribute( ComInterfaceType.InterfaceIsIUnknown )]
[ComImportAttribute()]
public interface IViewObject
{
    void Draw( [MarshalAs( UnmanagedType.U4 )] int dwDrawAspect, int lindex, IntPtr pvAspect, DVTARGETDEVICE ptd, IntPtr hdcTargetDev, IntPtr hdcDraw, COMRECT lprcBounds, COMRECT lprcWBounds, IntPtr pfnContinue, int dwContinue );
    int GetColorSet( [MarshalAs( UnmanagedType.U4 )] int dwDrawAspect, int lindex, IntPtr pvAspect, DVTARGETDEVICE ptd, IntPtr hicTargetDev, out tagLOGPALETTE ppColorSet );
    int Freeze( [MarshalAs( UnmanagedType.U4 )] int dwDrawAspect, int lindex, IntPtr pvAspect, out IntPtr pdwFreeze );
    int Unfreeze( [MarshalAs( UnmanagedType.U4 )] int dwFreeze );
    int SetAdvise( [MarshalAs( UnmanagedType.U4 )] int aspects, [MarshalAs( UnmanagedType.U4 )] int advf, [MarshalAs( UnmanagedType.Interface )] IAdviseSink pAdvSink );
    void GetAdvise( [MarshalAs( UnmanagedType.LPArray )] out int[] paspects, [MarshalAs( UnmanagedType.LPArray )] out int[] advf, [MarshalAs( UnmanagedType.LPArray )] out IAdviseSink[] pAdvSink );
}

I would just try this definition, but I get a few types that are unknown: DVTARGETDEVICE, COMRECT, tagLOGPALETTE. So my next question is, what assembly needs to be referenced to use these types?

+2  A: 

DVTARGETDEVICE and COMRECT are structures. You can find their definitions on pinvoke.net.

tagLOGPALETTE is a class. There is a sample available at http://blogs.msdn.com/vsod/archive/2008/11/01/resizing-the-embedded-ole-objects-using-net.aspx.

In addition, IViewObject and the three referenced types are all used internally by the .NET Framework. If you grab yourself a copy of Reflector (http://www.red-gate.com/products/reflector/), you can view existing implementations in System.Windows.Forms.UnsafeNativeMethods.

Nicole Calinoiu
How is it that there are many different implementations of this? Microsoft.VisualStudio.Ole.Interop has a different implementation of IViewObject than is used in System.Windows.Forms.UnsafeNativeMethods.
Josh Close
The differences lie in the details of mapping between managed and unmanaged types, which are not verified at compile time. In general, there may be more than one way to skin a p/invoke cat, but at least some of the possible approaches may bomb in at least some scenarios. For example, if an unmanaged method returns a 64-bit integer but your p/invoke declaration declares the return type to be a 32-bit integer, your call will work until the day that you hit a value that's too big for a 32-bit integer.
Nicole Calinoiu