国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
VS2005自定義ActiveX控件在asp.net中應(yīng)用方法
VS2005自定義ActiveX控件在asp.net中應(yīng)用方法
開發(fā)環(huán)境為VS 2005, .NET framework 2.0

文件—>新建—>項(xiàng)目     
彈出下面對(duì)話框
 
選擇Windows 控件庫   輸入名稱TestControl    點(diǎn)擊“確定”
在設(shè)計(jì)窗口中拖入控件 label1  timer  2個(gè)button  如下圖:
 
1. COM的接口和類創(chuàng)建
COM 接口(Interface):IMonitor 
Code
 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using System.ComponentModel;
 5using System.Runtime.InteropServices;
 6
 7namespace TestControl
 8{
 9    [
10        Guid("b505d5bb-2318-4fc9-8e91-6346cdd6fc91"),
11        InterfaceType(ComInterfaceType.InterfaceIsDual),
12        ComVisible(true)
13    ]
14    public interface IMonitor
15    {
16        void LoadControl(string sClassroom);
17        void UnloadControl();
18    }
19}
20
COM 類(Class):Monitor 
Code
 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Drawing;
 5using System.Data;
 6using System.Text;
 7using System.Windows.Forms;
 8using System.Runtime.InteropServices;
 9
10namespace TestControl
11{
12    [
13        Guid("b505d5bb-2318-4fc9-8e91-6346cdd6fc91"),
14        ProgId("TestControl.Monitor"),
15        ClassInterface(ClassInterfaceType.None),
16        ComDefaultInterface(typeof(IMonitor)),
17        ComVisible(true)
18    ]
19    public partial class Monitor : UserControl,IMonitor, IObjectSafety
20    {
21        public Monitor()
22        {
23            InitializeComponent();
24        }
25
26        public void LoadControl(string msg)
27        {
28            if (timer.Enabled == false)
29            {
30                timer.Start();
31            }
32        }
33        public void UnloadControl()
34        {
35            if (timer.Enabled == true)
36            {
37                timer.Stop();
38            }
39        }
40
41        private void timer_Tick(object sender, EventArgs e)
42        {
43            label1.Text = DateTime.Now.ToString();
44        }
45
46
47        private void Monitor_Load(object sender, EventArgs e)
48        {
49
50        }
51
52        private void button1_Click(object sender, EventArgs e)
53        {
54            timer.Enabled = true;
55            LoadControl("開始計(jì)時(shí)");
56        }
57
58        private void button2_Click(object sender, EventArgs e)
59        {
60            timer.Enabled = false;
61            UnloadControl();
62        }
63    }
64}
1)GUID 指定該類或者接口的GUID。

2)聲明屬性InterfaceType(ComInterfaceType.InterfaceIsDual),ComVisible(true),以支持register 和 unregister。
3)  IMonitor 是COM interface。C# 的COM Class 可以繼承自COM interface 也可以不用interface.

2 實(shí)現(xiàn)IObjectSafety 接口

微軟IObjectSafety 接口定義, GUID 為固定值, 一般不要修改,也可以重新生成GUID    在菜單欄   工具—>創(chuàng)建GUID
聲明:
ObjectSafety
Code
 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using System.Runtime.InteropServices;
 5
 6namespace TestControl
 7{
 8    [
 9        Serializable,
10        ComVisible(true)
11    ]
12    public enum ObjectSafetyOptions
13    {
14        INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001,
15        INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002,
16        INTERFACE_USES_DISPEX = 0x00000004,
17        INTERFACE_USES_SECURITY_MANAGER = 0x00000008
18    };
19
20    //
21    // MS IObjectSafety Interface definition
22    //
23    [
24        ComImport(),
25        Guid("b505d5bb-2318-4fc9-8e91-6346cdd6fc91"),
26        InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
27    ]
28    public interface IObjectSafety
29    {
30        [PreserveSig]
31        long GetInterfaceSafetyOptions(ref Guid iid, out int pdwSupportedOptions, out int pdwEnabledOptions);
32
33        [PreserveSig]
34        long SetInterfaceSafetyOptions(ref Guid iid, int dwOptionSetMask, int dwEnabledOptions);
35    };
36}
37
Monitor實(shí)現(xiàn):
Code
 1[IObjectSafety implementation]#region [IObjectSafety implementation]
 2        private ObjectSafetyOptions m_options = ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_CALLER |
 3           ObjectSafetyOptions.INTERFACESAFE_FOR_UNTRUSTED_DATA;
 4
 5        public long GetInterfaceSafetyOptions(ref Guid iid, out int pdwSupportedOptions, out int pdwEnabledOptions)
 6        {
 7            pdwSupportedOptions = (int)m_options;
 8            pdwEnabledOptions = (int)m_options;
 9            return 0;
10        }
11
12        public long SetInterfaceSafetyOptions(ref Guid iid, int dwOptionSetMask, int dwEnabledOptions)
13        {
14            return 0;
15        }
16        #endregion
  
如需轉(zhuǎn)載請(qǐng)加入本人Blog地址    

IObjectSafety 是一個(gè)接口,它可將其功能顯露給 Internet Explorer的“設(shè)置腳本安全性”和“設(shè)置初始化安全性”安全特性。
3.注冊(cè)和卸載
如果Class 聲明中使用了 InterfaceType ,ComVisible(true) 屬性,并且項(xiàng)目屬性頁設(shè)置 點(diǎn)擊“生產(chǎn)”的 “為COM interop 注冊(cè)” 項(xiàng)為TRUE,那么VS編譯該項(xiàng)目可自動(dòng)為Class注冊(cè)。
也可以使用VS2005 自帶工具 regasm.exe 手動(dòng)注冊(cè)和卸載 Class,可以用VS 自帶工具oleview 查看是否注冊(cè)成功

 
4.測試 以及調(diào)試
1)創(chuàng)建測試頁面     解決方案右鍵 添加—>新建網(wǎng)站 Default.aspx
Code
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
 
CABARC.EXE -s 6144 n  ClassroomViewerControl.cab ClassroomViewerControl.msi ClassroomViewerControl.inf
-s 6144:為簽名留下6k的空間 n 創(chuàng)建cab
5) 簽名,col.pfx 為密鑰
 signtool sign /f col.pfx ClassroomViewerControl.cab

6) 修改WEB PAGE hello.html并將CAB 拷貝到codebase指定的URL
<object id="Monitor" classid="clsid:627AD403-FA50-4a08-B875-770520865DD6" Width="640" Height="360" codebase="http://localhost/TestControl/ClassroomViewerControl.cab"> </object>
 

6.最后看一下效果
安裝隱藏了msi 安裝界面,類似于cabarc 打包ocx 的效果(點(diǎn)擊install 之后其他的都后臺(tái)做了)
注意:IE中沒有彈出.cab安裝窗口   如下圖:
 

這就需要設(shè)置IE的安全選項(xiàng)
IE瀏覽器里的  工具—>Internet 選項(xiàng)—>安全
 
點(diǎn)擊“自定義級(jí)別” 彈出下列窗口
 
將ActiveX 控件和插件的相關(guān)選項(xiàng)都啟用   點(diǎn)擊“確定”
再次測試 如果彈出“Windows已經(jīng)阻止此軟件因?yàn)闊o法驗(yàn)證發(fā)行者”提示
 
點(diǎn)擊“站點(diǎn)”
 
將 htt://localhost  和 http://10.122.89.28/  本機(jī)IP 添加進(jìn)去
下面的復(fù)選框的勾去掉才能添加
 
本文來自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/hankwen/archive/2009/03/02/3950397.aspx
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服