Microsoft KB Archive/814664

= PRB: ActiveX Error When You Sink Managed Events in Internet Explorer Script =

Article ID: 814664

Article Last Modified on 6/5/2003

-

APPLIES TO


 * Microsoft .NET Framework 1.0
 * Microsoft Internet Explorer 5.5
 * Microsoft Internet Explorer (Programming) 6.0
 * Microsoft .NET Framework 1.1

-



SYMPTOMS
When you sink managed events in Internet Explorer script, you may receive the following warning message:

An ActiveX control on this page is not safe. Your current security settings prohibit running unsafe controls on this page. As a result this page may not display as intended



WORKAROUND
To work around this problem, create a dummy interface and then implement the newly created interface in a MyWindowControl class that exists already. Make the following modifications to the code: ... public interface MyDummyInterface { } [System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None),System.Runtime.InteropServices.ComSourceInterfaces(typeof(ControlEvents))] public class MyWindowControl : System.Windows.Forms.UserControl,MyDummyInterface { ... }



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior:
 Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. In the New Project dialog box, click Visual C# Projects under Project Types, and then click Windows Control Library under Templates. Name the project ActiveXSourcing and then select ..\Inetpub\wwwroot as the Location. Click OK.  Copy and then paste the following code in the control window: using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices;

namespace ActiveXSourcing {   public delegate void ClickEventHandler(int x, int y);

// Source interface for events to be exposed // Add GuidAttribute to the source interface to supply an explicit System.Guid. // Add InterfaceTypeAttribute to indicate that interface is the IDispatch interface.

[System.Runtime.InteropServices.GuidAttribute(&quot;0422D916-C11A-474e-947D-45A107038D12&quot;) ]

[System.Runtime.InteropServices.InterfaceTypeAttribute(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch)] public interface ControlEvents

// Add a DisIdAttribute to any members in the source interface to        // specify the COM DispId. {       [System.Runtime.InteropServices.DispIdAttribute(0x60020000)] void ClickEvent(int x, int y); }

// Add a ComSourceInterfaces attribute to the control to identify       //the list of interfaces that are exposed as COM event sources.

[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None),System.Runtime.InteropServices.ComSourceInterfaces(typeof(ControlEvents))] public class MyWindowControl : System.Windows.Forms.UserControl //, ComInteropControlInterface {

System.Windows.Forms.TextBox tx = new TextBox;

private void InitializeComponent {

this.Name = &quot;MyWindowControl&quot;;

}

event ActiveXSourcing.ClickEventHandler ClickEvent;

public MyWindowControl : base {

initMyWindowControl;

}

private void initMyWindowControl {

Size = new System.Drawing.Size(300, 50); tx.Text = &quot;Click the text box to invoke 'ClickEvent'&quot;; tx.Size = this.Size; tx.Click += new System.EventHandler(ClickHandler); this.Controls.Add(tx);

}

private void ClickHandler(object sender, System.EventArgs e)       { if (ClickEvent != null) {               ClickEvent(0, 0); }       }    } }  To create a test HTML page, right-click the project node in Solution Explorer ,and then click Add New Item.</li> Select HTML page under Template, and then name the file Default.htm .</li>  Paste the following code in Default.htm: <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;> <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1' />

<HTML> <HEAD> <TITLE>Sink managed event in Internet Explorer</TITLE> </HEAD> <BODY> <OBJECT id=&quot;ctrl&quot; classid=&quot;http://localhost/ActiveXSourcing/bin/debug/ActiveXSourcing.dll#ActiveXSourcing.MyWindowControl&quot;> </OBJECT> <SCRIPT LANGUAGE=&quot;JScript&quot;> function ctrl::ClickEvent(a,b) {                  alert(&quot;MyWindowControl_ClickEvent&quot;); }       </SCRIPT> </BODY> </HTML> </li> Compile the control as a DLL.</li>  Use the following code to turn off the security on the control: caspol -s off </li> Open Internet Explorer. Locate the following Web page: http://localhost/ActiveXSourcing/default.htm</li></ol>

<div class="references_section">