How to make a COM DLL?

2019-09-06 13:43发布

问题:

Just another of those things that I have never done before but which is probably simple ... when you know how

I am using VB Express 2008 and need to create a very simple DLL.

I already built and tested it and now I find that it has to be a COM DLL. How do I go about that?


Edit: in reply to @Kman - I looked at http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comvisibleattribute.aspx

and changed my code to

Imports System.Runtime.InteropServices

Namespace My_DLL

  <ClassInterface(ClassInterfaceType.AutoDual)> _
  Public Class My_DLL

      <ComVisible(True)> Public Sub Function_A()
      End Sub

      <ComVisible(True)> Public Sub Function_B()
      End Sub
  End Class
End Namespace

but I still don't the functions using DLL Explorer, whereas I do see them in the old DLL ...

回答1:

Check http://www.codeproject.com/KB/COM/nettocom.aspx

Maybe http://www.exforsys.com/tutorials/vb.net-2005/creating-and-managing-components-in-vb.net-2005-section-1.html

The MS pages about it are here: http://msdn.microsoft.com/en-us/library/3x7357ez%28vs.71%29.aspx

Follow the suggestions and if you want to learn more check out the following book .NET and Com the Complete Interoperability Guide. Everything is explained there in whatever detail you like.



回答2:

Qualify your dll for interop; mark its ComVisibleAttribute to true.

Right click your project, goto Build tab, and check the last Checkbox, which says "register for COM interop".