1) 创建Visual Studio解决方案 "ActiveXSolution"。
2)在解决方案ActiveXSolution中添加 Windows窗体应用程序 “CSDemo”。
1. 在Windows窗体Form1添加代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CSDemo
{public partial class Form1 : Form{//返回给web的值public string dialogResult = string.Empty;//获取从web中传过来的值private string caption = string.Empty;private string text = string.Empty;public Form1(){InitializeComponent();}public Form1(string caption, string text){InitializeComponent();this.caption = caption;this.text = text;}private void Form1_Load(object sender, EventArgs e){Button btnTest = new Button();btnTest.Text = "测试";btnTest.Location = new Point(10, 10);btnTest.Click+=new EventHandler(btnTest_Click);this.Controls.Add(btnTest);}/// <summary>/// 显示从web传来的值/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void btnTest_Click(object sender, EventArgs e){dialogResult = MessageBox.Show(text,caption,MessageBoxButtons.OKCancel,MessageBoxIcon.Information,MessageBoxDefaultButton.Button1).ToString();this.Close();}}
}

3) 在解决方案ActiveXSolution中添加 Windows窗体控件库“ActiveXDemo”。
1. 在“ActiveXDemo”中添加接口“IObjectSafety.cs”代码如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ActiveXDemo
{[ComImport, Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")][InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]public interface IObjectSafety{[PreserveSig]void GetInterfacceSafyOptions(int riid,out int pdwSupportedOptions,out int pdwEnabledOptions);[PreserveSig]void SetInterfaceSafetyOptions(int riid,int dwOptionsSetMask,int dwEnabledOptions);}
}

2. 在“ActiveXDemo”中添加 用户控件“UserControl1.cs”代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace ActiveXDemo
{[Guid("413f087e-95b4-4eb4-9941-da0610f71fef")]public partial class UserControl1 : UserControl, IObjectSafety{public UserControl1(){InitializeComponent();}public void GetInterfacceSafyOptions(int riid, out int pdwSupportedOptions, out int pdwEnabledOptions){pdwSupportedOptions = 1;pdwEnabledOptions = 2;}public void SetInterfaceSafetyOptions(int riid, int dwOptionsSetMask, int dwEnabledOptions){throw new NotImplementedException();}public string ShowForm(string caption, string text){string dialogResult = string.Empty;//将web传过来的值传给winformCSDemo.Form1 frm = new CSDemo.Form1(caption, text);frm.ShowDialog();//将winform传过来的值传给webdialogResult = frm.dialogResult;return dialogResult;}}
}

3.右击“ActiveXDemo”—属性—生成—勾上为COM互操作注册。
4.打开“ActiveXDemo”—Properties—AssemblyInfo.cs将[assembly: ComVisible(false)]改成[assembly: ComVisible(true)]

4)在解决方案ActiveXSolution中创建安装项目“SetupDemo”
1. 右击安装项目“SetupDemo”—添加—项目输出—主输出“ActiveXDemo”
2. 安装“SetupDemo”
3. 单击:开始—所有程序—Microsoft Windows SDK v6.0A—Tools—OLE-COM Object Viewer,打开.NET Category可以看到ActiveXDemo.UserControl1

5)在解决方案ActiveXSolution中添加 ASP.NET Web应用程序 “BSDemo”

1.Default.aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BSDemo._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><title></title><script language="javascript" type="text/javascript">function fun(caption, text) {//将参数传给winform,并获取winform返回的值var dialogResult = document.getElementById('controlbyid').ShowForm(caption, text);alert(dialogResult);}</script>
</head>
<body><form id="form1" runat="server"><div><object id="controlbyid" classid="clsid:413f087e-95b4-4eb4-9941-da0610f71fef" codebase="Resource/SetupDemo.cab"></object><asp:Button ID="btnTest" runat="server" Text="Button" /></div></form>
</body>
</html>

2.Default.aspx.cs代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace BSDemo
{public partial class _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){string caption = "a1";string text = "b1";this.btnTest.Attributes.Add("onclick", "fun('"+caption+"','"+text+"');");}}}
}

6)生成SetupDemo.cab
1.网上下载cabsdk.exe
2.解压csbsdk.exe,将SetupDemo.msi放到解压后文件的BIN下面。
3.在BIN中创建install.inf
代码如下:
[version]
signature="$CHICAGO$"
AdvancedINF=2.0
[Setup Hooks]
hook1=hook1  
[hook1]
run=msiexec.exe /i "%EXTRACT_DIR%\SetupDemo.msi" /qn
4.开始-运行,输入“CMD”,在打开的命令提示符界面中,进入解压后文件的BIN目录,
输入:cabarc n SetupDemo.cab SetupDemo.msi install.inf
5.cab生成成功,将SetupDemo.cab放到“BSDemo”下面的Resource文件夹下。
6.启动网站,一般情况下,网页会弹出提示,是否安装ActiveX控件等,如果提示了也不能安装,需要将网站添加到信任站点,并允许下载不安全和未签名控件。关于控件的签名和认证,本文不做说明,需要的请自行搜索。

7)用VS创建证书。

1.开始—所有程序—Microsoft Visual Studio 2008—Visual Studio Tools—Visual Studio 2008 命令提示。
2.makecert -r -pe -n "CN=zhcao-demo" -ss My -sky exchange
3.查看证书:
打开ie—工具—Internet选项—内容—证书—我们将在个人中看到我们刚才创建的证书“zhcao-demo”。

8)给cab包添加证书
1.开始—所有程序—Microsoft Visual Studio 2008—Visual Studio Tools—Visual Studio 2008 命令提。
2.signtool signwizard—下一步—浏览获取我们前面创建的SetupDemo.cab—下一步—典型—从存储区选择—选择我们前面创建的证书“zhcao-demo”—确定—下一步—下一步—下一步—完成。

C#BS通过ActiveX控件及制作CAB包来调CS相关推荐

  1. C#开发ActiveX控件及制作CAB包

    一个项目要用到 ActiveX 控件,参照网上众多的例子,ActiveX控件倒是很容易就搞出来了: 然后做了一个[ 安装项目],倒是可以使用,只不过需要在客户端手动点击安装,下一步,下一步-觉得不是很 ...

  2. 【转】从网页上下载控件时制作CAB包的方法

    Internet 软件分发单位是"软件包",它由包含 .inf 文件或软件分发 (.osd) 文件(或两者都包括)的 CAB 文件 (.cab) 所组成.一个分发单位也可以包含软件 ...

  3. 写了一段VBA代码后, Excel每次保存时都弹出警告:”此文档中包含宏、Activex控件、XML扩展包信息“(office 2007)

    前言:今天在写一段VBA代码之后,遇到一个问题, Excel每次保存时就报一个警告(使用的是office 2007): 此文档中包含宏.Activex控件.XML扩展包信息 用起来很不爽! ----- ...

  4. ActiveX控件打包成Cab置于网页中自动下载安装

    From: http://www.iteye.com/topic/110834 makeCAB.rar (188.5 KB) [背景] 做过ActiveX控件的朋友都知道,要想把自己做的ActiveX ...

  5. ActiveX控件打包成Cab实现浏览器自动下载安装

    前言 我们在浏览器中使用我们自己的一些OCX,或者是DLL这一类的文件,在X86的机器上需要我们手动将这些文件拷贝到Windows/System32 文件夹下面去,然后通过Dos命令regsvr32 ...

  6. ActiveX控件打包成Cab置于网页中自动下载安装 (收藏未实践测试)

    from http://blog.csdn.net/htqlhy/article/details/7937897?locationNum=12 [背景]         做过ActiveX控件的朋友都 ...

  7. ActiveX控件打包成Cab置于网页中自动下载安装(转载)

    原文出自http://www.iteye.com/topic/110834 [背景] 做过ActiveX控件的朋友都知道,要想把自己做的ActiveX控件功能放在自己的网页上使用,那么用户在客户端就必 ...

  8. ActiveX控件之制作图片属性页

    本例可以通过属性页设置你的图片(IPictureDisp)类型的属性 1.添加Picture属性(get/set methods,LPPICTUREDISP类型),添加成员变量CPictureHold ...

  9. VC6开发视频监控ActiveX控件总结

    总结前段时间在VC6下使用MFC开发视频监控控件过程中遇到的一些问题. 1.获取控件当前所在路径,用于读取该目录下的INI配置文件 获取配置文件路径 2.获取当前运行控件的电脑上的固定盘符列表,用于本 ...

最新文章

  1. 用计算机算出手机号码,手机计算器开根号怎么按(万能科学计算器在线使用方法)...
  2. electron 改变窗体 大小_8个瑜伽常见体式变体,小改变,大不同!
  3. html5 滤色,深入理解CSS mix-blend-mode滤色screen混合模式
  4. Coding:C++类定义实现部分成员函数
  5. Kettle能做什么?
  6. UE4 集成讯飞听写插件
  7. 浏览器用户脚本管理器(Tampermonkey)
  8. php图片中不显示文字内容,水印效果 只有图片,文字不显示
  9. setState同步异步场景
  10. 强悍的 Linux —— grep 与 egrep
  11. 游戏设计情境探秘之动画
  12. 破防了,原来这才是机房运维的正确方法
  13. 基于用户的协同过滤推荐算法(整合)
  14. 营销数字化转型行业实践
  15. Java机器学习库(Java ML)(二、聚类)
  16. Rust_lings
  17. YYC松鼠短视频系统v3.5版本--稳定版本---优化性能以及各处接口返回以及部分ui页面细节
  18. 计算机硬件——显示器原理
  19. buddypress主题_WordPress Gone Social-BuddyPress
  20. [转载] Elasticsearch如何做到亿级数据查询毫秒级返回

热门文章

  1. IEEE引用格式规则及示例
  2. Vue中slot与slot-scope的理解及使用
  3. 基于php目标奖罚管理系统
  4. 土圭垚㙓数学课(四)空间变换
  5. 2021年山东大学程序设计精英挑战赛 真题
  6. pytorch CUDNN_STATUS_MAPPING_ERROR
  7. DXC Technology Company旗下公司Luxoft完成对CMORE Automotive的收购
  8. 2021-05-16 C#.NET面试题 列举你知道的数字格式化转换
  9. 关于APP安装来源统计的分析
  10. 如何减少页面的重绘和回流(14)