By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,286 Members | 2,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,286 IT Pros & Developers. It's quick & easy.

Consuming managed events within Internet Explorer

P: n/a
Hello and thank you in advance for your help.

Can anyone think of a reason why this code would work properly on one PC,
but not another?

I've got a System.Windows.Forms.UserControl that products events which I
want to consume (sink) within Internet Explorer.

I'm following the instructions at:
ms-http://support.microsoft.com/default.aspx?kbid=313891.

On one computer, Internet Explorer can call methods on the UserControl and
can sink events generated by this managed code.

Using the same code on another computer, Internet Explorer can call methods
on this UserControl, but can not sink the events this managed code is
generating.

The UserControl is written in Visual Studio 2003 using C#. The framework
version is "v1.1.4322" on both computers.

The operating system on the computer where the code works (call methods on
the UserControl + sink events generated by the UserControl in IE) is: XP sp2
+ all the latest Windows Updates.

The operating system on the computer where the code does NOT work (call
methods on the UserControl only) is: XP sp1 + all the latest Windows Updates.

Here's a copy of the C# UserControl code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace TestWUCEventer
{
#region EventDelegates

/// <summary>
/// Delegate invoked when a NOTIFY event occurs.
/// </summary>
public delegate void sssNotifyEventHandler(string getResultXml);

/// <summary>
/// Delegate invoked when a SURVEY event occurs.
/// </summary>
public delegate void sssSurveyEventHandler();

#endregion

#region Outgoing COM Interfaces

/// <summary>
/// This interface is for raising SDK events to COM clients.
/// </summary>
[GuidAttribute("4AF6A157-AD81-4da3-8FF7-1AD1135D0645")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
public interface ISDKEvents
{
/// <summary>
/// Raise the NOTIFY event to COM clients.
/// </summary>
/// <param name="getResultXml">The string that is passed with the NOTIFY
event.</param>
[DispIdAttribute(0x60020010)]
void NotifyEvent(string getResultXml);

/// <summary>
/// Raise a SURVEY event to COM clients.
/// </summary>
[DispIdAttribute(0x60020011)]
void SurveyEvent();
}

#endregion

#region Incomming COM Interfaces

public interface ISDKClient
{
/// <summary>
/// Raise the NOTIFY event.
/// </summary>
/// <param name="IncludeWithNotify">Data passed with the NOTIFY
event.</param>
void RaiseNotifyEvent(string IncludeWithNotify);

/// <summary>
/// Raise the SURVEY event.
/// </summary>
void RaiseSurveyEvent();

/// <summary>
/// Simple test for accessing Windows Control Library method from web page
displayed in IE.
/// </summary>
/// <returns>Hello World</returns>
string TestMessage();

/// <summary>
/// Start the timer which automatically raises events.
/// </summary>
void StartTimer();
}

#endregion

/// <summary>
/// Summary description for UserControl1.
/// </summary>
[ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(ISDKEvents))]
public class EventGenerator : System.Windows.Forms.UserControl, ISDKClient
{
#region EventsRaised

/// <summary>
/// Event is raised when a SURVEY occurs.
/// </summary>
public event sssSurveyEventHandler SurveyEvent;

/// <summary>
/// Event raised when a NOTIFY occurs.
/// </summary>
public event sssNotifyEventHandler NotifyEvent;

#endregion

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Timer eventTimer = null;
private enum EventType { SURVEY, NOTIFY };
private EventType lastEvent = EventType.SURVEY;

public EventGenerator()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

// Start our eventTimer.
eventTimer = new Timer();
eventTimer.Tick += new EventHandler(eventTimer_Tick);
eventTimer.Interval = 2000;
eventTimer.Enabled = false;
// eventTimer.Start();
}

/// <summary>
/// Start a timer that automatically raises events.
/// </summary>
public void StartTimer()
{
eventTimer.Enabled = true;
eventTimer.Start();
}

/// <summary>
/// Simple test for accessing Windows Control Library method from web page
displayed in IE.
/// </summary>
public string TestMessage()
{
return ("Hello World");
}

/// <summary>
/// Call RaiseNotifyEvent to cause a NOTIFY event to be raised.
/// </summary>
/// <param name="IncludeWithNotify">Any string to include as the data of
the NOTIFY event.</param>
public void RaiseNotifyEvent(string IncludeWithNotify)
{
try
{
if (NotifyEvent != null)
{
NotifyEvent(IncludeWithNotify);
}
}
catch (Exception exc)
{
throw (exc);
}
}

/// <summary>
/// Call RaiseSurveyEvent to cause a SURVEY event to be raised.
/// </summary>
public void RaiseSurveyEvent()
{
try
{
if (SurveyEvent != null)
SurveyEvent();
}
catch (Exception exc)
{
throw (exc);
}
}

private void eventTimer_Tick(object sender, EventArgs e)
{
// Stop the timer until we're done with this method.
eventTimer.Stop();

if (lastEvent == EventType.SURVEY)
{
// Raise a NOTIFY event.
RaiseNotifyEvent("This is a test string.");

// Record the last event raised.
lastEvent = EventType.NOTIFY;
}
else
{
// Raise a NOTIFY event.
RaiseSurveyEvent();

// Record the last event raised.
lastEvent = EventType.SURVEY;
}

// Start the timer again.
eventTimer.Start();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// EventGenerator
//
this.Name = "EventGenerator";
this.Size = new System.Drawing.Size(1, 1);

}
#endregion

}
}

Here's a copy of the web page that runs in Internet Explorer:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="EventTesterWeb.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" id="SurveyEventHandler" event="SurveyEvent"
for="ssClient">
alert("SURVEY event");
</script>
<script language="javascript" id="NotifyEventHandler"
event="NotifyEvent(notifyResultXml)" for="ssClient">
alert("NOTIFY event: " + notifyResultXml);
</script>
<script id="WebPageScript" language="javascript">
function OnWebPageLoad()
{
// Try calling the test method.
document.all.lblDisplayMessage.outerText = ssClient.TestMessage();
}
function StartTimer()
{
ssClient.StartTimer();
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" onload="javascript:OnWebPageLoad();">
<OBJECT id="ssClient"
classid="http:TestWUCEventer.dll#TestWUCEventer.Ev entGenerator" height="32"
width="32">
</OBJECT>
<form id="Form1" method="post" runat="server">
<asp:Label id="lblDisplayMessage" style="Z-INDEX: 101; LEFT: 8px;
POSITION: absolute; TOP: 8px"
runat="server" Width="240px">Nothing yet...</asp:Label>
<input type="button" value="Start Timer"
onclick="javascript:StartTimer();" />
</form>
</body>
</HTML>

Apr 17 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Have you compared the Internet Explorer security settings on the two
machines? You may find the one that doesn't work is due to a security
restriction or setting which isn't in force on the machine where your
code does work.

Other than that, try making sure the platforms are as similar as
possible - it could be an SP2 / SP1 thing.

Cheers, M

Apr 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.