Visual Basic Development Bookmark and Share   
 Home > Visual Basic Interop and Upgrade > How to create a dll that can be referenced in VBA or vb6
 

How to create a dll that can be referenced in VBA or vb6

I am trying to create a Com Class dll in VB.Net 2008 which will be accessable from VBA and VB6.

I have choosen Class Library.
Then added a New COM Class
I deleted the original Class1 .vb

I added my code.
I added <Assembly: ClassInterface(ClassInterfaceType.AutoDual)> to my Com Class. It already had a ComClass entry
I made sure "Register for COM interopp" was checked in the project>properties>Compile screen.

After a build I move the .dll, .tlb and the snk to a server.

I would like to leave the dll on the server rather than install it on every workstation (but I could put it on every workstation if that is my problem).
Since I am also testing on the server I use RegAsm to register the assembly.

I have tried both

regasm M:\email\sendemail.dll /codebase M:\email\sendemail.dll
and

regasm M:\email\sendemail.dll /tlb:M:\email\sendemail.tlb /codebase M:\email\sendemail.dll

The second one overwrites the .tlb created by visual studio.

I even dragged the .dll into the C:\windows\assembly directory and unregistered the assembly.

Regardless of what I have tried, I cannot add the dll as a reference in Excel 2003.

The message I receive is:
"Can't add a refernce to the specied file"

I can add the .tld file. When I add the .tlb file I can see the properties and methods. But when I run the code I get ActiveX component cannot create object. (this is the error message I get when using the VS version of the.tlb. The message is different when I use the .tlb which is generated by the RegAsm.)

I have read many many google results but still nothing that has gotten me going.

It can't be this difficult. What am I missing???

thanks,
pat

Here is the code. I have removed all of the properties except for one and I have stripped everything out of the method, except the one line. I hope this helps.

Imports System.Net
Imports System.Net.Mail
Imports System.Runtime.InteropServices
'
<Assembly: ClassInterface(ClassInterfaceType.AutoDual)>
<ComClass(SendEmailClass.ClassId, SendEmailClass.InterfaceId, SendEmailClass.EventsId)> _
'
Public Class SendEmailClass
'
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "187d8992-b211-44f7-9bf0-9be98129905c"
Public Const InterfaceId As String = "2ca24656-528b-42a2-bed0-a1452d70c0de"
Public Const EventsId As String = "e8f8d4e7-ee4d-47e8-8b30-765111c27ec0"
#End Region
'
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
'
Private ToStringM As String
'
Public Property ToAddressString() As String
Get
Return ToStringM
End Get
Set(ByVal Value As String)
ToStringM = Value
End Set
End Property

Public Sub SendMail()
Dim mail As New Mail.MailMessage
mail.To.Add(ToStringM)

End Sub
End Class

mpdillon56  Sunday, November 15, 2009 8:57 PM
Not really sure why you want to run this DLL from the network but in order to do so you will have to provide full trust to the share.

http://blogs.msdn.com/shawnfa/archive/2004/12/30/344554.aspx

BTW, ClickOnce Deployment may be an option you want to consider for distribution of the DLLto the workstations.


Paul ~~~~ Microsoft MVP (Visual Basic)
Paul P Clement IV  Wednesday, November 18, 2009 8:27 PM
Not really sure why you want to run this DLL from the network but in order to do so you will have to provide full trust to the share.

http://blogs.msdn.com/shawnfa/archive/2004/12/30/344554.aspx

BTW, ClickOnce Deployment may be an option you want to consider for distribution of the DLLto the workstations.


Paul ~~~~ Microsoft MVP (Visual Basic)
Paul P Clement IV  Wednesday, November 18, 2009 8:27 PM

You can use google to search for other answers

Custom Search

More Threads

• VB6 to VB.Net Error List Slow Refresh
• Visual Basic 6.0 Upgrade Assessment Tool "Application Error"
• VB6 Upgrade Path
• reading from excel from vb2008 - w/o opening excel
• VB6 Forms in .NET 3.0 application
• Can one target the 3.5 Framework [as the default] using the Upgrade Wizard within VS 2008 (migrating VB6 project to VB.Net)?
• Converting VB6 to VS2008 - Trouble reading a field value.
• Multiple vb.net Interop controls or forms in same vb6 project
• Is there a tool for "cloning" a COM library?
• InterOpUserControl