?? ??? ?? ??? ???? ???? ????? ???? ???????? ??????? ?? ??? ???????? ???? (COM) ??????? (????????? ???) ?? ?????? ???? ?? ??? ?? ?? .NET Windows ???????? ?????? ?????? ?? ???, ???? ?????? ???????? ????? COM ??????? ?? ?? ?? Internet Explorer ??? ????????? ?? ????? ????
????? ?? COM ?? ???????? ???????? ?? ????? ???? ???? ?? ???? ??? ??????? ?? ??? ????? Microsoft .NET Framework ?????? ?? ???????????? ???????? ??????:
??????????
????? ???? outlines ???????? ?????????, ??????????, ??????? ??????, ?? ???? ???? ???:
- Microsoft Visual Studio .NET
- Microsoft Internet Explorer (????????????) ?? ??? ?? ??????? 5.5 ???????
???? ???? ?? ??? ????? ??? Internet Explorer ????????? ????? ???????? ????
- ??? ????? Windows ??????? ???????? ?????:
- Microsoft Visual Studio .NET ???? ????..
- ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????.
- ???????? ?????????????? ????? ???, ????? ????????? C# ??????????? ???????????????? ???????? ????-????? ????, ?? ???? ???Windows ???????? ??????????? ???????????????.
- ??? ????? ???????? ?? ????? ???? ???? ?? ??? ????? ?? ??? ????????? ?????
- ????? ???GuidAttribute???? ????? ??????? ?? ??? ??? ???????? ?? ?? ???? ??? ?? ??????? ?? ??? Guid ?????? ?? ??? ?? ????????? constructor ???? ?? ??? ??? ???????? ???? ?????? ??? ?? ??? ????? ???? ???? ?? GUID ?? ????? ?? ??? Guidgen.exe ????? ?? ????? ?? ???? ???
[GuidAttribute("0422D916-C11A-474e-947D-45A107038D12") ]
public interface ControlEvents
{
// Insert code here.
}
- ????? ???InterfaceType??????? ?? ??? ??? COM ?? ??????? ???? ?? ??? ????? ??????? ?? ??? ???IDispatch??????? ?? ???:
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface ControlEvents
{
// Insert code here.
}
- ????? ???DispIdAttributeCOM ?? ????????? ???? ?? ??? ????? ??????? ??? ???? ?? ????? ?? ??? ?????????? (DISPID) ?? ??? ???? ?? ???? ????? ?? ?????:
public interface ControlEvents
{
[DispIdAttribute(0x60020000)]
void ClickEvent(int x, int y);
}
- ??????? ???? ?? ??? ?????? ????? ?? ?????? ?? ??? ??? ??? ????? ?????? ??????
- ????? Windows ??????? ???????? ?? ????? ???????? ??????????? ?????
- ????? ???ComSourceInterfaces??????? ???????? COM ????? ????? ?? ??? ??? ????????? ?? ???? ?? ??????? ?? ??? ???????? ???? ?? ???:
[ClassInterface(ClassInterfaceType.None),ComSourceInterfaces(typeof(ControlEvents))]
public class MyWindowControl : System.Windows.Forms.UserControl
{
// Insert code here.
}
- ???????? ?? ?? ????????-???? ????????? (DLL) ???? ?? ??? ??? ?????? ?????
- ????? hook ???? ?? ??? HTML ??? ?? ??? ????????? ????? ?? ?????? ?????? ?? ???::
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<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="ctrl" classid="YourDllName.dll#ActiveXSourcing.MyWindowControl">
</OBJECT>
<SCRIPT LANGUAGE="JScript">
function ctrl::ClickEvent(a,b)
{
alert("MyWindowControl_ClickEvent");
}
</SCRIPT>
</BODY>
</HTML>
- ??? ??????? ?????? ?? ??????? ?????? ??? ?? ???-??? ?????? ???? .NET Framework ???????????? ????? (Mscorcfg.msc) ?? ????? ?????
??? ??????? ?????
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 IDispatch interface.
[GuidAttribute("0422D916-C11A-474e-947D-45A107038D12") ]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface ControlEvents
//Add a DisIdAttribute to any members in the source
//interface to specify the COM DispId.
{
[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.
[ClassInterface(ClassInterfaceType.None),ComSourceInterfaces(typeof(ControlEvents))]
public class MyWindowControl : System.Windows.Forms.UserControl
//, ComInteropControlInterface
{
System.Windows.Forms.TextBox tx = new TextBox();
private void InitializeComponent()
{
this.Name = "MyWindowControl";
}
event ActiveXSourcing.ClickEventHandler ClickEvent;
public MyWindowControl() : base()
{
initMyWindowControl();
}
private void initMyWindowControl()
{
Size = new System.Drawing.Size(300, 50);
tx.Text = "Click on the TextBox to invoke 'ClickEvent'";
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);
}
}
}
}
???? ??????? ?? ???, ????? Microsoft ??? ???? ?? ??? ??????:
???????? ??????? ?? ???, ???? ?? ???? ?????? ?? ????? ?? ???? ?? Microsoft ???????? ??? ?????::
316510
(http://support.microsoft.com/kb/316510/EN-US/
)
BUG: Security Exception When You Use Event Handlers in Internet Explorer
???? ID: 313891 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
- Microsoft Visual C# .NET 2002 Standard Edition
| kbcominterop kbhowto kbhowtomaster kbsample kbmt KB313891 KbMthi |
???? ?????? ??????????????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:
313891
(http://support.microsoft.com/kb/313891/en-us/
)