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

ⅰ亾dé卋堺 提交于 2020-01-03 05:11:11

问题


How do I access a COM component from an ASP.NET page. I added reference to my ASP.NET project.

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.

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.

How do I use those methods in the code behind from default.aspx.vb.


回答1:


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. By convention, it named it 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:

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). If ePadIIu happens to be a STA COM component you might experience:

  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:

  • COM Interoperability in the .NET Framework
  • Running ASMX services on STA Threads
  • Developing High Performance ASP.NET Websites
  • ASP.NET Hang and OutOfMemoryException caused by STA Components

Good Luck!
Z



来源:https://stackoverflow.com/questions/1390203/how-do-i-use-a-com-component-from-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!