Creating VB.Net COM component to use in VBScript.


W

Wake-Up-Jeff

I am trying to create a VB.Net COM DLL which I can use in VBScript.
I followed the steps in the following article:
http://msdn2.microsoft.com/en-us/library/x66s8zcd(VS.71).aspx
(I used the method "with COM class template")

My DLL got created fine (I guess) - no errors in build process.
The "Make Assembly COM-Visible" checkbox is checked.

I then created a vbscript which tried to create an instance of the object:
i.e.
set obj = CreateObject("Test")

However, I always receive the error
"ActiveX can't create object 'Test'"

I tried registering the DLL by using regasm, but still got the error.

Can anyone advise what I am missing?

Sample code for the VB.Net app follows:

<ComClass(Test.ClassId, Test.InterfaceId, Test.EventsId)> _
Public Class Test

#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 = "7d75a31e-3ef9-4b31-9647-1e0f6d3729de"
Public Const InterfaceId As String =
"f19ce7ce-b85f-4d59-a187-c8e3fc9cb67b"
Public Const EventsId As String = "105f085a-2e06-4958-9de2-5aa642f966fc"
#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 Add(ByVal i1 As Integer, ByVal i2 As Integer) As Integer
Add = i1 + i2
End Function
End Class
 
Ad

Advertisements

K

Ken Halter

Wake-Up-Jeff said:
Can anyone advise what I am missing?

Well.. the .vb.com group's for pre-dotNet versions of VB, so if you want
only relevant answers, you can remove that from the crosspost list
 
G

Guest

Wake-Up-Jeff said:
I then created a vbscript which tried to create an instance of the object:
i.e.
set obj = CreateObject("Test")

I think it should be something like:

Set obj = CreateObject ("ClassLibrary1.Test")

depending on the class and class library names.
 
M

Michel Posseth [MCP]

I think it should be something like:

Set obj = CreateObject ("ClassLibrary1.Test")

depending on the class and class library names.

Almost :)

Set obj = CreateObject ("namespacename.classToInitiateName")

In 80% of the times the namespacename is the same as the assemblyname, but
if you followed the patterns and practices library the rootnamespace should
be the company name

Also a .Net Com object that needs the posibility to be created with
CreateObject must have a public sub new ( you may leave it empty if you do
not need a initializer but it must be there )

regards

Michel
 
W

Wake-Up-Jeff

Thanks. That worked perfectly.
Appreciate your assistance.
Jeff.
Michel Posseth said:
I think it should be something like:

Set obj = CreateObject ("ClassLibrary1.Test")

depending on the class and class library names.

Almost :)

Set obj = CreateObject ("namespacename.classToInitiateName")

In 80% of the times the namespacename is the same as the assemblyname, but
if you followed the patterns and practices library the rootnamespace
should be the company name

Also a .Net Com object that needs the posibility to be created with
CreateObject must have a public sub new ( you may leave it empty if you do
not need a initializer but it must be there )

regards

Michel
 
Ad

Advertisements

G

Guest

Hi Jeff,

I'm trying to achieve the exact same results but cannot seem to get my DLL
registered with regasm. Can you advise on the command line you are using to
register your DLL on a non-development machine?

Also, do you happen to have more than one class in your VB solution?
Are you using Visual Studio 9.0?

You don't seem to have an Interface in your code- some postings I find
indicate you need to define an interface but some postings do not. Can you
tell me what the difference would be? I have tried it both ways but doesn't
seem to make a difference on my target machine.

The DLL works just fine on my development machine where I compiled it but I
believe that is because Visual Studio automatically did the necessary
registrations for me.

Thanks for any comments you can add.



Wake-Up-Jeff said:
Thanks. That worked perfectly.
Appreciate your assistance.
Jeff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top