1. 找到COM的组件名,如"MSXML2.DOMDocument.3.0". 可以在注册表中去看.(HKEY_CLASSES_ROOT\...)
2. 在JS中创建对象:xmldoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
3. 在对象上调用方法xmldoc.loadXML("xxxxxxx");
实例:查看MDACD版本.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<script language="JavaScript">
<!--
var ver ;
ver = new ActiveXObject("MDACVer.Version");
alert (ver.Major);
//-->
</script>
</body>
</html>
晴天的例子:
C#代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace WindowsControlLibrary1
{
public interface INewsMonitor
{
// 发送文件时,记录发送者,接收者和发送的文件名发送文件时,记录发送者,接收者和发送的文件名#region 发送文件时,记录发送者,接收者和发送的文件名
/**/
/**/
/**/
/// <summary>
/// 当发送文件时,记录发送者,接收者和发送的文件名
/// </summary>
/// <param name="strSendID">文件发送者</param>
/// <param name="strTargetID">文件接受者</param>
/// <param name="strFileName">文件名</param>
// [DispId(8)]
void SendFile(string strSendID, string strTargetID, string strFileName);
// 接收文件时,记录文件接收者,发送者和发送的文件名接收文件时,记录文件接收者,发送者和发送的文件名#region 接收文件时,记录文件接收者,发送者和发送的文件名
/**/
/**/
/**/
/// <summary>
/// 接受文件时,记录文件接收者,发送者和发送的文件名
/// </summary>
/// <param name="strReceiveID">文件接收者</param>
/// <param name="strSendID">文件发送者</param>
/// <param name="strFileName">文件名</param>
// [DispId(2)]
void RecvFile(string strReceiveID, string strSendID, string strFileName);
//文件发送成功后,记录发送者,接收者和发送的文件名文件发送成功后,记录发送者,接收者和发送的文件名#region 文件发送成功后,记录发送者,接收者和发送的文件名
/**/
/**/
/**/
/// <summary>
/// 文件发送成功后,记录发送者,接收者和发送的文件名
/// </summary>
/// <param name="strSendID">文件发送者</param>
/// <param name="strTargetID">文件接收者</param>
/// <param name="strFileName">文件名</param>
// [DispId(3)]
void FileSendOK(string strSendID, string strTargetID, string strFileName);
//取消文件发送时,记录发送者,接收者和发送的文件名取消文件发送时,记录发送者,接收者和发送的文件名#region 取消文件发送时,记录发送者,接收者和发送的文件名
/**/
/**/
/**/
/// <summary>
/// 取消文件发送时,记录发送者,接收者和发送的文件名
/// </summary>
/// <param name="strCancelID">取消文件发送者</param>
/// <param name="strTargetID">文件发送对方</param>
/// <param name="strFileName">文件名</param>
// [DispId(4)]
void FileSendCancel(string strCancelID, string strTargetID, string strFileName);
void say();
} // end interface INewsMonitor
public interface IMove
{
void say();
}
[Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IObjectSafety
{
// methods
void GetInterfacceSafyOptions(
System.Int32 riid,
out System.Int32 pdwSupportedOptions,
out System.Int32 pdwEnabledOptions);
void SetInterfaceSafetyOptions(
System.Int32 riid,
System.Int32 dwOptionsSetMask,
System.Int32 dwEnabledOptions);
}
[Guid("1EA4DBF0-3C3B-11CF-810C-00AA00389B73")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public partial class MyUserControl : UserControl, INewsMonitor, IObjectSafety, IMove
{
public void GetInterfacceSafyOptions(Int32 riid, out Int32 pdwSupportedOptions, out Int32 pdwEnabledOptions)
{
// TODO: 添加 WebCamControl.GetInterfacceSafyOptions 实现
pdwSupportedOptions = 1;
pdwEnabledOptions = 2;
}
public void SetInterfaceSafetyOptions(Int32 riid, Int32 dwOptionsSetMask, Int32 dwEnabledOptions)
{
// TODO: 添加 WebCamControl.SetInterfaceSafetyOptions 实现
}
public MyUserControl()
{
InitializeComponent();
}
public void say()
{
MessageBox.Show("aaaaaaaaaaaaa");
}
private void UserControl1_Load(object sender, EventArgs e)
{
}
private string filePath = string.Empty;
private string writeLine = string.Empty;
private void NewsMsg()
{
StreamWriter sw = null;
if (File.Exists(filePath))
{
sw = File.AppendText(filePath);
}
else
{
FileStream fs = File.Create(filePath);
sw = new StreamWriter(fs);
}
sw.WriteLine(writeLine);
sw.Close();
}
//送文件时,记录发送者,接收者和发送的文件名#region 发送文件时,记录发送者,接收者和发送的文件名
/**/
/// <summary>
/// 当发送文件时,记录发送者,接收者和发送的文件名
/// </summary>
/// <param name="strSendID">文件发送者</param>
/// <param name="strTargetID">文件接受者</param>
/// <param name="strFileName">文件名</param>
public void SendFile(string strSendID, string strTargetID, string strFileName)
{
filePath = @"c:MsgMonitorSendFile.txt";
writeLine = strSendID + " 向 " + strTargetID + " 发送 < " + strFileName + " > 文件";
NewsMsg();
}
//接收文件时,记录文件接收者,发送者和发送的文件名#region 接收文件时,记录文件接收者,发送者和发送的文件名
/**/
/// <summary>
/// 接受文件时,记录文件接收者,发送者和发送的文件名
/// </summary>
/// <param name="strReceiveID">文件接收者</param>
/// <param name="strSendID">文件发送者</param>
/// <param name="strFileName">文件名</param>
public void RecvFile(string strReceiveID, string strSendID, string strFileName)
{
filePath = @"c:MsgMonitorRecvFile.txt";
writeLine = strReceiveID + " 接收到 " + strSendID + " 发送的 < " + strFileName + " > 文件";
NewsMsg();
}
//文件发送成功后,记录发送者,接收者和发送的文件名#region 文件发送成功后,记录发送者,接收者和发送的文件名
/**/
/// <summary>
/// 文件发送成功后,记录发送者,接收者和发送的文件名
/// </summary>
/// <param name="strSendID">文件发送者</param>
/// <param name="strTargetID">文件接收者</param>
/// <param name="strFileName">文件名</param>
public void FileSendOK(string strSendID, string strTargetID, string strFileName)
{
filePath = @"c:MsgMonitorFileSendOK.txt";
writeLine = strSendID + " 已经成功向 " + strTargetID + " 发送 < " + strFileName + " > 文件";
NewsMsg();
}
//取消文件发送时,记录发送者,接收者和发送的文件名#region 取消文件发送时,记录发送者,接收者和发送的文件名
/**/
/// <summary>
/// 取消文件发送时,记录发送者,接收者和发送的文件名
/// </summary>
/// <param name="strCancelID">取消文件发送者</param>
/// <param name="strTargetID">文件发送对方</param>
/// <param name="strFileName">文件名</param>
public void FileSendCancel(string strCancelID, string strTargetID, string strFileName)
{
filePath = @"c:MsgMonitorFileSendCancel.txt";
writeLine = strCancelID + " 取消和 " + strTargetID + " 发送 < " + strFileName + " > 文件";
NewsMsg();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
使用ole view查看progid:
使用regeditt查看progid:
javascript访问:
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function makecall()
{
var myobj=new ActiveXObject("WindowsControlLibrary1.MyUserControl");
myobj.say();
alert(state);
}
</SCRIPT>
<input type="button" onclick="makecall()" />