|
-
Aug 17th, 2007, 02:03 AM
#1
Thread Starter
Fanatic Member
[2005] Making a DLL Com-visible (i.e. for Vbscript)
I have the following code in a Class Library
Code:
Imports System
Imports System.Reflection
Namespace Managed
Public Class MetaClass
Public Function GetAssembly(ByVal pathname As String) As Assembly
Return Assembly.Load(pathname)
End Function
End Class
End Namespace
In the Assembly Information I have selected "Make assembly COM-visible". In the Compile options I have selected "Register for COM Interop".
I have registered the resultant TLB file with VBRegTLB.exe.
However, I am still unable to reference this using Vbscript (i.e. it doesn't show up as scriptable COM object).
Can anyone tell me what I'm doing wrong?
ManagePC - the all-in-one PC management and inventory tool
-
Aug 17th, 2007, 02:23 AM
#2
Re: [2005] Making a DLL Com-visible (i.e. for Vbscript)
You need to register your assembly as a COM component and then install it in the GAC. Open a VS Command Prompt window and navigate to your output folder, then run statements like these:
Code:
regasm /tlb:MyProject.tlb MyProject.dll
gacutil /i MyProject.dll
You may already have executed the first command but I'd guess you haven't done the second. When you need to update the component you need to first uninstall and unregister it:
Code:
gacutil /u MyProject
regasm /u MyProject.dll
before registering and installing the new version.
-
Aug 17th, 2007, 02:46 AM
#3
Thread Starter
Fanatic Member
Re: [2005] Making a DLL Com-visible (i.e. for Vbscript)
Ah ok thanks. I had also, in the meantime, done it by defining it as a COM Class
Code:
Imports System.Reflection
Namespace Managed
<ComClass(MetaClass.ClassId, MetaClass.InterfaceId, MetaClass.EventsId)> _
Public Class MetaClass
#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 = "715d9ea0-3534-453e-bcab-998df80cdd01"
Public Const InterfaceId As String = "cac73659-5e61-4eba-a084-3ca7cc25b3b4"
Public Const EventsId As String = "e966000c-d742-4213-b86e-8cb17db599ce"
#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
Public Function GetAssembly(ByVal pathname As String) As Assembly
Return Assembly.Load(pathname)
End Function
End Class
End Namespace
ManagePC - the all-in-one PC management and inventory tool
-
Aug 17th, 2007, 02:48 AM
#4
Thread Starter
Fanatic Member
Re: [2005] Making a DLL Com-visible (i.e. for Vbscript)
Cool, it works now though. Now I can use any function in any DLL in my VBscripts just by calling the GetAssembly method of my DLL!
Well, in theory anyway
ManagePC - the all-in-one PC management and inventory tool
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|