|
1、注冊(cè)組件 regsvr32 C:\WINDOWS\system32\HX.ocx 2、用Aximp.exe工具對(duì)HX.ocx做轉(zhuǎn)換,對(duì)APT.ocx再次封裝成兩個(gè)類庫(HX.dll,AxHX.dll) 3、代碼
1 using System;
2 using System.Data; 3 using System.IO; 4 using System.Messaging; 5 using System.Net; 6 using System.Text; 7 using System.Text.RegularExpressions; 8 using System.Threading; 9 using System.Web; 10 using System.Data.SqlClient; 11 using AXHH;//ocx控件 12 using HH;//ocx控件 using System.Windows.Forms; 13 namespace Ocx_test 14 { 15 public class Program 16 { 17 //設(shè)置靜態(tài)變量 18 static AXHH hh; 19 [STAThread] 20 static void Main(string[] args) 21 { 22 23 //初始化ocx控件 24 hh = new AXHH(); 25 //顯式調(diào)用該實(shí)例的CreateControl()方法才能調(diào)用其他方法否則在調(diào)用時(shí)系統(tǒng)將報(bào)AxHost.InvalidActiveXStateException異常 26 hh.CreateControl(); 27 28 //調(diào)用控件屬性及方法 29 hh.ip="127.0.0.1"; 30 hh.test(); 31 32 } 33 }
4、注意,如果是多線程調(diào)用,則在 線程名.Start() 前加上,例如:
線程名.SetApartmentState(System.Threading.ApartmentState.STA);//設(shè)置模式,必須在啟動(dòng)之前設(shè)置。
5、參考了 http://www.cnblogs.com/Jerryshome/archive/2011/04/21/2023183.html http://blog.sina.com.cn/s/blog_4a77f0630100imn9.html http://tech.it168.com/d/2008-05-12/200805120947628.shtml
但是反射的技術(shù)試了,不行,
System.Reflection.Assembly ass; comObjectName = ass.GetType("AxHH.AxHH");//必須使用名稱空間+類名稱
誰有知道,請(qǐng)告知,謝謝
|
|
|