//------------------------------------------------------------- //COM 的例子 //------------------------------------------------------------- [GuidAttribute("85E45398-B4BA-440e-9343-1E665E2AFCD8"),ComVisible(true)] public interface IFormDlg { [DispId(1)]bool DoModel(); [DispId(2)]void CloseDialog(); [DispId(3)]bool DoModeless(); [DispId(4)]bool IsShown{get;} }[ComVisible(true), GuidAttribute("D55CE299-16A3-4dd7-8530-406708FD9908"),ProgId("SureyorUIClassLibrary.ThreeButtonsDlg")] public class COMFormDlg:IFormDlg { private bool _isShown = false; private Thread _dlgThread; private static object _locker; //............ //........... public COMFormDlg(){} public COMFormDlg(string title, string msg) { //................... } public bool IsShown{get{return _isShown;}} // [ComRegisterFunctionAttribute] public static void RegisterFunction(Type t) { //代码..... } [ComUnregisterFunctionAttribute] public static void UnregisterFunction(Type t) { //代码...... } bool DoModel(){return true;} void CloseDialog(){throw new Exception("lsdkfsld");} bool DoModeless(){return true;} }
//------------------------------------------------------------- //COM+ 的例子 和COM是不同的 //------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Windows.Forms; using System.EnterpriseServices; using System.Runtime.InteropServices;namespace MyFunctions {
[InterfaceType(ComInterfaceType.InterfaceIsDual)] [ComVisible(true),GuidAttribute("169ABC84-9616-4af8-8068-7117A3BD4035")] public interface myInterFace { void RunCalc(); void RunWindowsExplorer(); int GetRandom(int min,int max); } [ProgId("My_Functions")] [ComVisible(true),GuidAttribute("5D7FED5B-20EC-4169-B0BC-EC3C2AB5D973")] public class Functions:ServicedComponent, myInterFace { public void RunWindowsExplorer() { try { System.Diagnostics.Process.Start("Explorer.exe"); } catch (Exception ex) { throw ex; } } public static bool RunCalc() { try { System.Diagnostics.Process.Start("calc.exe"); return true; } catch (Exception ex) { throw ex; } //return false; } public int GetRandom(int min,int max) { return int.MaxValue;
//COM 的例子
//-------------------------------------------------------------
[GuidAttribute("85E45398-B4BA-440e-9343-1E665E2AFCD8"),ComVisible(true)]
public interface IFormDlg
{
[DispId(1)]bool DoModel();
[DispId(2)]void CloseDialog();
[DispId(3)]bool DoModeless();
[DispId(4)]bool IsShown{get;}
}[ComVisible(true), GuidAttribute("D55CE299-16A3-4dd7-8530-406708FD9908"),ProgId("SureyorUIClassLibrary.ThreeButtonsDlg")]
public class COMFormDlg:IFormDlg
{
private bool _isShown = false;
private Thread _dlgThread;
private static object _locker;
//............
//...........
public COMFormDlg(){}
public COMFormDlg(string title, string msg)
{
//...................
}
public bool IsShown{get{return _isShown;}}
//
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
//代码.....
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type t)
{
//代码......
}
bool DoModel(){return true;}
void CloseDialog(){throw new Exception("lsdkfsld");}
bool DoModeless(){return true;}
}
//COM+ 的例子 和COM是不同的
//-------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using System.EnterpriseServices;
using System.Runtime.InteropServices;namespace MyFunctions
{
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true),GuidAttribute("169ABC84-9616-4af8-8068-7117A3BD4035")]
public interface myInterFace
{
void RunCalc();
void RunWindowsExplorer();
int GetRandom(int min,int max);
} [ProgId("My_Functions")]
[ComVisible(true),GuidAttribute("5D7FED5B-20EC-4169-B0BC-EC3C2AB5D973")]
public class Functions:ServicedComponent, myInterFace
{ public void RunWindowsExplorer()
{
try
{
System.Diagnostics.Process.Start("Explorer.exe");
}
catch (Exception ex)
{
throw ex;
}
} public static bool RunCalc()
{
try
{
System.Diagnostics.Process.Start("calc.exe");
return true;
}
catch (Exception ex)
{
throw ex;
}
//return false;
}
public int GetRandom(int min,int max)
{
return int.MaxValue;
}
}
}