Red Gate forums :: View topic - How to read param from html using an ActiveX object using C#
Return to RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
PInvoke.Net forum

How to read param from html using an ActiveX object using C#

Search in PInvoke.Net forum
Post new topic   Reply to topic
Jump to:  
Author Message

Joined: 18 Oct 2007
Posts: 1

PostPosted: Thu Oct 18, 2007 2:45 pm    Post subject: How to read param from html using an ActiveX object using C# Reply with quote


I have a problem with reading the param that is in the html code:

  <script LANGUAGE="JavaScript1.2">
   function Scrape( )
    var objDownload = new ActiveXObject( "TiborActiveX1.Download1" );
     objDownload.InvokeMethod( );
    catch(exception) {
     alert( "Failed" );
  <table align="center">
    <a href="javascript:Scrape( )">Invoke Component</a>
  <p>Please Wait...Downloading components...</p>
  <object name="secondobj" id='TestActivex'  classid='CLSID:A47C22B1-3CC3-45bc-801E-3FCC4FFD3E45' codebase=',0,0,0'>
<PARAM NAME="Server" VALUE="TestServer">

this is just a test. i've impelmented the ipersistpropertybag interface but my load method never seams to be called.

the code looks like this:


using System;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Diagnostics;

namespace TiborActiveX1
    interface IObjectSafety
        int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions);

        int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions);

    interface IPersistPropertyBag
        void InitNew();
        void Load (IPropertyBag propertyBag, int errorLog);
        void Save (IPropertyBag propertyBag, [InAttribute] bool clearDirty,[InAttribute] bool saveAllProperties);
        void GetClassID(out Guid classID);


    interface IPropertyBag
        void Write ([InAttribute] string propName,[InAttribute] ref Object ptrVar);
        void Read([InAttribute] string propName, out Object ptrVar, int errorLog);

    interface IDownload
        void InvokeMethod();
    /// <summary>
    /// COM exposed .Net class.
    /// </summary>
    public class Download1 : UserControl, IDownload, IObjectSafety, IPersistPropertyBag
        private object a;
        private Label label1;
        private string aa = "load not called";
        public Download1()

        // Constants for implementation of the IObjectSafety interface.
        private const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001;
        private const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002;
        private CheckBox checkBox1;
        private Button button1;
        private const int S_OK = 0;

        /// <summary>
        /// COM exposed Method.
        /// </summary>
        public void InvokeMethod()
            MessageBox.Show("ClientSide Component invoked sucessfully!!", "ClientSide Component", MessageBoxButtons.OK, MessageBoxIcon.Information);

        void IPersistPropertyBag.InitNew() { }
        void IPersistPropertyBag.GetClassID(out Guid classID) { classID = new System.Guid("A47C22B1-3CC3-45bc-801E-3FCC4FFD3E45"); }
        void IPersistPropertyBag.Load(IPropertyBag propertyBag, int errorLog)
            aa = "load called";
            object value;
            propertyBag.Read("Server",out value,errorLog);
            a = (string)value;

        void IPersistPropertyBag.Save(IPropertyBag propertyBag, [InAttribute] bool clearDirty, [InAttribute] bool saveAllProperties){}

        // Implementation of the IObjectSafety methods.
        int IObjectSafety.GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions)
            return S_OK;   // return S_OK

        int IObjectSafety.SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions)
            return S_OK;   // return S_OK

        private void InitializeComponent()
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            // checkBox1
            this.checkBox1.AutoSize = true;
            this.checkBox1.Location = new System.Drawing.Point(337, 91);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(80, 17);
            this.checkBox1.TabIndex = 0;
            this.checkBox1.Text = "checkBox1";
            this.checkBox1.UseVisualStyleBackColor = true;
            // button1
            this.button1.Location = new System.Drawing.Point(325, 153);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(102, 27);
            this.button1.TabIndex = 1;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // label1
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(197, 220);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 2;
            this.label1.Text = "label1";
            // Download1
            this.Name = "Download1";
            this.Size = new System.Drawing.Size(700, 392);


        private void button1_Click(object sender, EventArgs e)
            label1.Text = aa;
            if (this.checkBox1.Checked == true)
                this.checkBox1.Checked = false;
                this.checkBox1.Text = "1231231afas23123something hand written";
                this.checkBox1.Checked = true;
                this.checkBox1.Text =(string)a;

notice that in the button event i try to get even an info that the load was called but the aa value never changes from "not called"
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group