这里我们将介绍C#调用COM组件的几个步骤,先将Com类型信息转换为.NET元数据,然后查看元数据,最后测试程序。

首先将Com类型信息转换为.NET元数据

  1. tlbimp sample.dll /out: sample_clw.dll

工具:Tlbimp.exe(类型库导入程序 )

参考:.Net framework SDK 文档

  1. 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的方法

  1. using System;
  2. using sample_clw;
  3. namespace CompConsole
  4. {
  5. /// <summary>
  6. /// Class1 的摘要说明。
  7. /// </summary>
  8. class Class1
  9. {
  10. /// <summary>
  11. /// 应用程序的主入口点。
  12. /// Date:2003/6/20
  13. /// </summary>
  14. [STAThread]
  15. static void Main(string[] args)
  16. {
  17. //
  18. // TODO: 在此处添加代码以启动应用程序
  19. Console.Write ("=======Demo for Call com functions in c#=============\n");
  20. sampleClass sam = new sampleClass();
  21. //now we call functions
  22. //
  23. sam.SayHello();
  24. }
  25. }

相关文章:

  • 2021-08-10
  • 2021-11-29
  • 2021-10-10
  • 2021-10-13
  • 2022-01-31
  • 2022-02-28
  • 2022-12-23
  • 2021-06-30
猜你喜欢
  • 2021-08-24
  • 2022-12-23
  • 2021-09-06
  • 2022-01-24
  • 2021-08-29
  • 2022-12-23
  • 2022-01-12
相关资源
相似解决方案