Solved

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

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

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 19

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Build JSON from table records 17 40
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 33
LINQ question 7 21
Get String split 5 32
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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now