Solved

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

Posted on 2006-07-17
7
1,525 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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