Javascript调用COM组件

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:
[img]http://dl.iteye.com/upload/attachment/164718/37d5381c-8e6e-3941-882b-9dce1474d228.jpg[/img]
使用regeditt查看progid:
[img]http://dl.iteye.com/upload/attachment/164720/ada73b73-de36-3828-9b46-ba3d9c588372.jpg[/img]

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()" />

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值