Solved

c# Active Document Server / C# ActiveX Control / Communicating with Container

Posted on 2006-07-17
7
1,521 Views
Last Modified: 2008-01-09
Hello Experts,

I have created an ActiveX control in C# (almost an activex but it's a DLL and i had messed around with the registry) and it is contained inside IE.

What are the interfaces I need to implement in my c# UserControl for it to talk back and forth with the ActiveX container which is IE?

I didn't know if these are the right ones though:
IPersistFile, IOleObject, and IDataObject... based on this msdn page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_internet_first_steps.3a_.activex_documents.asp

Thanks in advance!
0
Comment
Question by:AlphaGuys
  • 2
  • 2
7 Comments
 

Author Comment

by:AlphaGuys
ID: 17125959
I tried implementing IOleObject in my usercontrol using these interfaces:

    [ComImport]
    [Guid("00000112-0000-0000-C000-000000000046")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IOleObject
    {
        void SetClientSite(IOleClientSite pClientSite);
        void GetClientSite(ref IOleClientSite ppClientSite);
        void SetHostNames(object szContainerApp, object szContainerObj);
        void Close(uint dwSaveOption);
        void SetMoniker(uint dwWhichMoniker, object pmk);
        void GetMoniker(uint dwAssign, uint dwWhichMoniker, object ppmk);
        void InitFromData(System.Runtime.InteropServices.ComTypes.IDataObject pDataObject, bool fCreation, uint dwReserved);
        void GetClipboardData(uint dwReserved, ref System.Runtime.InteropServices.ComTypes.IDataObject ppDataObject);
        void DoVerb(uint iVerb, uint lpmsg, object pActiveSite, uint lindex, uint hwndParent, uint lprcPosRect);
        void EnumVerbs(ref object ppEnumOleVerb);
        void Update();
        void IsUpToDate();
        void GetUserClassID(uint pClsid);
        void GetUserType(uint dwFormOfType, uint pszUserType);
        void SetExtent(uint dwDrawAspect, uint psizel);
        void GetExtent(uint dwDrawAspect, uint psizel);
        void Advise(object pAdvSink, uint pdwConnection);
        void Unadvise(uint dwConnection);
        void EnumAdvise(ref object ppenumAdvise);
        void GetMiscStatus(uint dwAspect, uint pdwStatus);
        void SetColorScheme(object pLogpal);
    };

    [ComImport]
    [Guid("00000118-0000-0000-C000-000000000046")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IOleClientSite
    {
        void SaveObject();
        void GetMoniker(uint dwAssign, uint dwWhichMoniker, ref object ppmk);
        void GetContainer(ref object ppContainer);
        void ShowObject();
        void OnShowWindow(bool fShow);
        void RequestNewObjectLayout();
    }

the thing is I can't get the SetClientSite(IOleClientSite pClientSite) to execute when my usercontrol is being loaded by IE. Am I missing a step here? I basically want to talk back to IE with my UserControl embedded on it.
0
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 17127477
Unless you're implementing events you want your user control to fire back at IE or JavaScript, you don't need to do anything.  It's automatic.  It took me a long time to figure this out myself.

Any public accessors or methods you have are available to IE via scripting.
0
 

Author Comment

by:AlphaGuys
ID: 17132255
The thing is, the object is not embedded in IE using the <object> tag. It is embedded in IE through MIME (I associated my viewer(my .net dll) with a certain file type). When a user navigates to that file type, my control automatically shows up inside IE (like surfing on a pdf file and adobe reader spawns inside IE automatically). Now I want to capture the filename that made my usercontrol show, I guess this is by getting the LocationURL property of the Explorer but first, I need to get a reference of the container where my usercontrol is sitting, which is IE. I tried Container but it is null. I implemented the IOleObject but the SetClientSite is not firing. I think I'm missing something...
0
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 17135171
Here's what I did to provide an interface for events from my user control.  Note this class is after the primary class:

    #region Additonal Classes and Interfaces
    /* New Class Definitions within the Namespace
       * They must be put down here otherwise we'll get
       * the "unable to find resource file" error.
       * Documented in:
       * http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318603
       * */

    /// <summary>
    /// EC31E0EE-2339-4933-9621-FCD5E41B74C6
    /// Exposes the DocumentLoadCompleted event to JavaScript
    /// </summary>
    [Guid("EC31E0EE-2339-4933-9621-FCD5E41B74C6")]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface ICachingControlCOMEvents
    {
        /// <summary>
        /// OnReady Event Declaration
        /// </summary>
        [DispId(0x60020000)]
        void OnReady();

        /// <summary>
        /// OnFileReady Event Declaration
        /// </summary>
        [DispId(0x60020001)]
        void OnFileReady();

        /// <summary>
        /// NextDoc Event Declaration
        /// </summary>
        [DispId(0x60020002)]
        void NextDoc();

        /// <summary>
        /// PrevDoc Event Declaration
        /// </summary>
        [DispId(0x60020003)]
        void PrevDoc();

        /// <summary>
        /// NextPage Event Declaration
        /// </summary>
        [DispId(0x60020004)]
        void NextPage();

        /// <summary>
        /// PrevPage Event Declaration
        /// </summary>
        [DispId(0x60020005)]
        void PrevPage();
    }
    #endregion

Follow this template and see what happens.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question