Solved

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

Posted on 2006-07-17
7
1,527 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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