PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET Creating VB.Net COM component to use in VBScript.

Reply

Creating VB.Net COM component to use in VBScript.

 
Thread Tools Rate Thread
Old 21-09-2007, 07:16 AM   #1
Wake-Up-Jeff
Guest
 
Posts: n/a
Default Creating VB.Net COM component to use in VBScript.


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


  Reply With Quote
Old 21-09-2007, 03:12 PM   #2
Ken Halter
Guest
 
Posts: n/a
Default Re: Creating VB.Net COM component to use in VBScript.

"Wake-Up-Jeff" <artvandal8@hotmail.com> wrote in message
news:O1qvlbB$HHA.4584@TK2MSFTNGP03.phx.gbl...
>
> 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

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm


  Reply With Quote
Old 21-09-2007, 05:22 PM   #3
=?Utf-8?B?dXJrZWM=?=
Guest
 
Posts: n/a
Default RE: Creating VB.Net COM component to use in VBScript.


"Wake-Up-Jeff" wrote:

> 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.

--
urkec
  Reply With Quote
Old 22-09-2007, 10:09 AM   #4
Michel Posseth [MCP]
Guest
 
Posts: n/a
Default Re: Creating VB.Net COM component to use in VBScript.


> 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



"urkec" <urkec@discussions.microsoft.com> schreef in bericht
news:B329665C-D6F7-4468-848D-D33B4CAE836F@microsoft.com...
>
> "Wake-Up-Jeff" wrote:
>
>> 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.
>
> --
> urkec
>



  Reply With Quote
Old 23-09-2007, 10:30 PM   #5
Wake-Up-Jeff
Guest
 
Posts: n/a
Default Re: Creating VB.Net COM component to use in VBScript.

OK, thanks for letting me know. I will note for future.
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:%23AZGBoF$HHA.4828@TK2MSFTNGP04.phx.gbl...
> "Wake-Up-Jeff" <artvandal8@hotmail.com> wrote in message
> news:O1qvlbB$HHA.4584@TK2MSFTNGP03.phx.gbl...
>>
>> 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
>
> --
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> In Loving Memory - http://www.vbsight.com/Remembrance.htm
>



  Reply With Quote
Old 23-09-2007, 10:30 PM   #6
Wake-Up-Jeff
Guest
 
Posts: n/a
Default Re: Creating VB.Net COM component to use in VBScript.

Thanks. That worked perfectly.
Appreciate your assistance.
Jeff.
"Michel Posseth [MCP]" <MSDN@posseth.com> wrote in message
news:e4ZazgP$HHA.1900@TK2MSFTNGP02.phx.gbl...
>
>> 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
>
>
>
> "urkec" <urkec@discussions.microsoft.com> schreef in bericht
> news:B329665C-D6F7-4468-848D-D33B4CAE836F@microsoft.com...
>>
>> "Wake-Up-Jeff" wrote:
>>
>>> 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.
>>
>> --
>> urkec
>>

>
>



  Reply With Quote
Old 29-10-2007, 03:13 PM   #7
=?Utf-8?B?QnJpYW4gS3VkZXJh?=
Guest
 
Posts: n/a
Default Re: Creating VB.Net COM component to use in VBScript.

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" wrote:

> Thanks. That worked perfectly.
> Appreciate your assistance.
> Jeff.
> "Michel Posseth [MCP]" <MSDN@posseth.com> wrote in message
> news:e4ZazgP$HHA.1900@TK2MSFTNGP02.phx.gbl...
> >
> >> 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
> >
> >
> >
> > "urkec" <urkec@discussions.microsoft.com> schreef in bericht
> > news:B329665C-D6F7-4468-848D-D33B4CAE836F@microsoft.com...
> >>
> >> "Wake-Up-Jeff" wrote:
> >>
> >>> 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.
> >>
> >> --
> >> urkec
> >>

> >
> >

>
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off