Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to cast a control to IOleObject
    primarykey
    data
    text
    <p>I want to invoke <strong>GetClientSite</strong> on a .net control. For this purpose I am trying to cast a control (in example Windows.Forms.Form) to <strong>IOleObject</strong> which returns null.</p> <p>What should I do to get IOleObject?</p> <pre><code>using System; using System.Runtime.InteropServices; using System.Security; using System.Windows.Forms; namespace Test001 { public class Form001 : Form { public Form001() { InitializeComponent(); } private void InitializeComponent() { this.SuspendLayout(); this.Name = "Form001"; this.Text = "Form001"; this.Load += new System.EventHandler(this.Form001_Load); this.ResumeLayout(false); } private void Form001_Load(object sender, EventArgs e) { IOleObject obj = (IOleObject) this; //IOleClientSite site = obj.GetClientSite(); } } [ComImport, Guid("00000112-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), SuppressUnmanagedCodeSecurity] public interface IOleObject { [PreserveSig] int SetClientSite([In, MarshalAs(UnmanagedType.Interface)] IOleClientSite pClientSite); IOleClientSite GetClientSite(); [PreserveSig] int SetHostNames([In, MarshalAs(UnmanagedType.LPWStr)] string szContainerApp, [In, MarshalAs(UnmanagedType.LPWStr)] string szContainerObj); [PreserveSig] int Close(int dwSaveOption); [PreserveSig] int SetMoniker([In, MarshalAs(UnmanagedType.U4)] int dwWhichMoniker, [In, MarshalAs(UnmanagedType.Interface)] object pmk); [PreserveSig] int GetMoniker([In, MarshalAs(UnmanagedType.U4)] int dwAssign, [In, MarshalAs(UnmanagedType.U4)] int dwWhichMoniker, [MarshalAs(UnmanagedType.Interface)] out object moniker); [PreserveSig] int InitFromData([In, MarshalAs(UnmanagedType.Interface)] IDataObject pDataObject, int fCreation, [In, MarshalAs(UnmanagedType.U4)] int dwReserved); [PreserveSig] int GetClipboardData([In, MarshalAs(UnmanagedType.U4)] int dwReserved, out IDataObject data); [PreserveSig] int DoVerb(int iVerb, [In] IntPtr lpmsg, [In, MarshalAs(UnmanagedType.Interface)] IOleClientSite pActiveSite, int lindex, IntPtr hwndParent, [In] object lprcPosRect); [PreserveSig] int EnumVerbs(out object e); [PreserveSig] int OleUpdate(); [PreserveSig] int IsUpToDate(); [PreserveSig] int GetUserClassID([In, Out] ref Guid pClsid); [PreserveSig] int GetUserType([In, MarshalAs(UnmanagedType.U4)] int dwFormOfType, [MarshalAs(UnmanagedType.LPWStr)] out string userType); [PreserveSig] int SetExtent([In, MarshalAs(UnmanagedType.U4)] int dwDrawAspect, [In] object pSizel); [PreserveSig] int GetExtent([In, MarshalAs(UnmanagedType.U4)] int dwDrawAspect, [Out] object pSizel); [PreserveSig] int Advise(object pAdvSink, out int cookie); [PreserveSig] int Unadvise([In, MarshalAs(UnmanagedType.U4)] int dwConnection); [PreserveSig] int EnumAdvise(out object e); [PreserveSig] int GetMiscStatus([In, MarshalAs(UnmanagedType.U4)] int dwAspect, out int misc); [PreserveSig] int SetColorScheme([In] object pLogpal); } [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000118-0000-0000-C000-000000000046")] public interface IOleClientSite { [PreserveSig] int SaveObject(); [PreserveSig] int GetMoniker([In, MarshalAs(UnmanagedType.U4)] int dwAssign, [In, MarshalAs(UnmanagedType.U4)] int dwWhichMoniker, [MarshalAs(UnmanagedType.Interface)] out object moniker); [PreserveSig] int GetContainer(out object container); [PreserveSig] int ShowObject(); [PreserveSig] int OnShowWindow(int fShow); [PreserveSig] int RequestNewObjectLayout(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload