c# 中调用COM组件

- 首先将Com类型信息转换为.NET元数据
tlbimp sample.dll /out: sample_clw.dll

工具:Tlbimp.exe(类型库导入程序 )
参考:.Net framework SDK 文档
ms-help://MS.NETFrameworkSDK.CHS/cptools/html/cpgrftypelibraryimportertlbimpexe.htm

查看元数据

工具:ILDasm
参考:ms-help://MS.NETFrameworkSDK.CHS/cptutorials/html/il_dasm_tutorial.htm

测试程序
生成一个console programme
在project->add reference里,选择com,browser你的com,select
ok,现在在你的bin目录下应该有一个sample_clw.dll了

下面我们来用sample_clw的方法

using System;
using sample_clw;
namespace CompConsole
{
///

1<summary>   
2/// Class1 的摘要说明。   
3/// </summary>

class Class1
{
///

1<summary>   
2/// 应用程序的主入口点。 
3
4/// Date:2003/6/20   
5/// </summary>

[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
Console.Write ("=======Demo for Call com functions in c#=============\n");

sampleClass sam = new sampleClass();
//now we call functions
//
sam.SayHello();
}
}
}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus