C# UserControl in IE, no events
Awesome!
That fixed the problem.
Here's the final code that worked, I also had to implement IObjectSafety so
IE wouldn't block the events and show the "security ribbon" at the top of
the page.
namespace EventTest
{
[ComImport]
[Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
interface IObjectSafety
{
[PreserveSig]
int GetInterfaceSafetyOptions(ref Guid riid, out int
pdwSupportedOptions, out int pdwEnabledOptions);
[PreserveSig]
int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask,
int dwEnabledOptions);
}
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h)]
[Guid("6C4ED6D6-AA34-4538-BEF7-BA287AFF6BF2"), ComVisible(true)]
public interface IClientControlEvents
{
[DispId(1)]
void InfoMessage(string message);
}
public delegate void InfoMessageEventHandler(string data);
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IClientControlEvents)), ComVisible(true)]
public partial class UplTest : System.Windows.Forms.UserControl,
IObjectSafety
{
public event InfoMessageEventHandler InfoMessage;
protected string akito = "Ow! Starrt";
// Constants for implementation of the IObjectSafety interface.
private const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001;
private const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002;
private const int S_OK = 0;
public UplTest()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (InfoMessage != null)
InfoMessage("Wahoo!");
else
label1.Text = "No handler";
}
public string Akito
{
get { return akito; }
set {
akito = value;
label1.Text = akito;
}
}
// Implementation of the IObjectSafety methods.
int IObjectSafety.GetInterfaceSafetyOptions(ref Guid riid, out int
pdwSupportedOptions, out int pdwEnabledOptions)
{
pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA;
pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA;
return S_OK; // return S_OK
}
int IObjectSafety.SetInterfaceSafetyOptions(ref Guid riid, int
dwOptionSetMask, int dwEnabledOptions)
{
return S_OK; // return S_OK
}
}
}
Thanks for your help!
Mike N.
|