简体   繁体   English

如何使用VB.NET中的COM组件?

[英]How do I use a COM component from VB.NET?

How do I access a COM component from an ASP.NET page. 如何从ASP.NET页访问COM组件。 I added reference to my ASP.NET project. 我添加了对我的ASP.NET项目的引用。

The actual dll I got from the 3rd party is ePadIIu.dll but when I added it to the ASP.NET project it shows as ePadIIu.interop . 我从第三方获得的实际dll是ePadIIu.dll但是当我将其添加到ASP.NET项目时,它显示为ePadIIu.interop

I want to access all the methods and properties in the component. 我想访问组件中的所有方法和属性。

The sample I received from the 3rd party software uses vbscript to access all the methods. 我从第三方软件收到的样本使用vbscript访问所有方法。

How do I use those methods in the code behind from default.aspx.vb . 如何在default.aspx.vb后面的代码中使用这些方法。

When you added the reference to the COM component from your ASP.NET project, Visual Studio ran it through tblimp (type library import utility) to generate an interop assembly for use with .NET. 当您将引用从ASP.NET项目添加到COM组件时,Visual Studio会通过tblimp(类型库导入实用程序)运行该引用,以生成供.NET使用的互操作程序集。 By convention, it named it ePadIIu.interop.dll. 按照惯例,它命名为ePadIIu.interop.dll。

If you view this reference in the Object Browser, you should be able to determine the namespace you will need to reference, as well as any of the classes, properties and methods exposed. 如果在对象浏览器中查看此引用,则应该能够确定需要引用的命名空间,以及所公开的任何类,属性和方法。

Your using statement at the top of your *.cs might look something like this: 您在* .cs顶部的using语句可能看起来像这样:

using ePadIIu;

Caution - Slippery When Wet 注意-湿滑
VB COM components are notorious for being compiled using a Single Threaded Apartment (STA) - though not always the case (if I remember correctly). VB COM组件因使用单线程单元(STA)进行编译而臭名昭著-尽管并非总是如此(如果我没有记错的话)。 If ePadIIu happens to be a STA COM component you might experience: 如果ePadIIu恰好是STA COM组件,则您可能会遇到:

  1. Slower performance 性能较慢
  2. Possible memory leak due to blocked finalizer (not trying to be all doom and gloom, just seems to happen more often than not) 由于终结器被阻止而可能导致内存泄漏(并非全是厄运和阴郁,似乎更经常发生)

References discussing the problem: 讨论该问题的参考文献:

Good Luck! 祝好运!
Z ž

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM