Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-17
7
Medium Priority
?
1,544 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

705 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