Problem Using VB.net Class Library DLL in VBScript

G

Guest

I am trying to create one DLL that I can use in vbscripting that has all of
the common codes and other additional input forms, controls, etc. I have
DIS.DLL, namespace is DLL, and so far have written four COM Classes (Project
| Add Item | Com Class) so it automatically generates the GUID's for each of
my classes. Sample code for one of my classes is below.

On my development machine I can create this object just fine and call the
properties using Set DataGridView = CreateObject("DIS.DataGridView") and is
working as expected.

On my integration machine I tried dropping the DLL in C:\DIS and:
1. Double clicking on it to register to regsvr32 but get the error that the
entry point cannot be found
2. Using a regasm.exe tool that I have read about for COM classes, but get
an error saying -Failed to load DIS.DLL because it is not a valid .NET
assembly
3. Tried using gacutil.exe but am getting an error saying -Failure adding
assembly to the cache: unknown error.

Furthermore when I try to create the object in vbscript it will say it
cannot create the activeX component.

Any suggestions on how I can get this DLL in a usable state on
non-development machines?

====================================================
Imports System.IO
Imports System.Windows.Forms

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

#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 = "33e160c9-03f9-4142-b7fc-226fe49e920a"
Public Const InterfaceId As String =
"9dd5b3d6-5be8-409e-8c79-bb0388c0ed98"
Public Const EventsId As String = "d168723a-78dc-4b3d-a84a-97a998d2ca09"
#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

Dim strMyFormName As String = "Data Grid View"
Dim MyDataGridView As New frmDataGridView()
Dim intCountColumn As Integer = 0
Dim intCountRow As Integer = 0
Dim intColumnIndexToValidate As Integer = -1
Dim dataDataTable As New DataTable()
Dim strSortQuery As String = ""

Public Sub AddColumn(ByVal strColumnName As String, ByVal blnReadOnly As
Boolean)

Dim colColumn As New DataGridViewTextBoxColumn
dataDataTable.Columns.Add(strColumnName)
colColumn.DataPropertyName = strColumnName
colColumn.ReadOnly = blnReadOnly
colColumn.HeaderText = strColumnName
colColumn.SortMode = DataGridViewColumnSortMode.Programmatic
MyDataGridView.dgvMyDataGrid.Columns.Add(colColumn)
Me.intCountColumn = Me.intCountColumn + 1

End Sub

Public Function DisplayDataGridView() As Boolean
...
End Function

...
...
End Class
 
G

Guest

I'm going to try to include more detail that I already tried from reading
other posts:

1. I have verified that the AssemblyInfo.vb file in my project has
<Assembly: ComVisible(True)> .
2. In my project compile properties, I do have checked the 'Register for COM
interop.
3. Per another tutorial that I tried to follow, to register a .NET COM
object in the GAC, it has to be signed, so I created a key on the signing
settings of my project without a password and without the 'Delay sign only'
option.

I read a post from 2005 that mentioned including register and unregister
functions in your classes- is this what I am missing?
 
P

Phill W.

Brian said:
I am trying to create one DLL that I can use in vbscripting that has all of
the common codes and other additional input forms, controls, etc. I have
DIS.DLL, namespace is DLL, and so far have written four COM Classes (Project
| Add Item | Com Class) so it automatically generates the GUID's for each of
my classes. Sample code for one of my classes is below.
On my integration machine I tried dropping the DLL in C:\DIS and:
1. Double clicking on it to register to regsvr32 but get the error that the
entry point cannot be found
A .Net assembly, even one designed for Interop, is not a valid 32-bit
executable and can't be fed directly into Regsvr32.
2. Using a regasm.exe tool that I have read about for COM classes, but get
an error saying -Failed to load DIS.DLL because it is not a valid .NET
assembly

That's worrying. Your .Net Assembly is not a valid .Net assembly???
3. Tried using gacutil.exe but am getting an error saying -Failure adding
assembly to the cache: unknown error.
GacUtil and Regasm are entirely different tools for entirely different
different purposes.

Running regasm on your development machine (which the "Register for
InterOp" option does for you) should create you a Type Library (.tlb).
This contains all the COM definitions required.

Use RegTLib.exe on the target machine to "register" the .tlb.

HTH,
Phill W.
 
G

Guest

Thanks Phill for your advice. I've never read anything before about
registering the tbl file on the target machine. I didn't anticipate exposing
the tbl file on the target machine either as I do not need our customers to
know which classes are accessible via COM. In our C++ MFC DLL's that we
currently use in our VB Scripts we did not release the tbl files to our
client machines. Is this something different in the .NET world?

I found the RegTLib.exe on the target machine in the i386 folder and it
appears to have worked okay, however when I try to create the object in a
VbScript it still says it is unable to create the ActiveX component.

=================================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Monitor>cd c:\i386

C:\i386>regtlib c:\ingen\disprog\dis.tlb
Registration of c:\ingen\disprog\dis.tlb successful.

C:\i386>
=================================================
 
L

Lloyd Sheen

Brian Kudera said:
Thanks Phill for your advice. I've never read anything before about
registering the tbl file on the target machine. I didn't anticipate
exposing
the tbl file on the target machine either as I do not need our customers
to
know which classes are accessible via COM. In our C++ MFC DLL's that we
currently use in our VB Scripts we did not release the tbl files to our
client machines. Is this something different in the .NET world?

I found the RegTLib.exe on the target machine in the i386 folder and it
appears to have worked okay, however when I try to create the object in a
VbScript it still says it is unable to create the ActiveX component.

=================================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Monitor>cd c:\i386

C:\i386>regtlib c:\ingen\disprog\dis.tlb
Registration of c:\ingen\disprog\dis.tlb successful.

C:\i386>
=================================================


Phill W. said:
A .Net assembly, even one designed for Interop, is not a valid 32-bit
executable and can't be fed directly into Regsvr32.


That's worrying. Your .Net Assembly is not a valid .Net assembly???

GacUtil and Regasm are entirely different tools for entirely different
different purposes.

Running regasm on your development machine (which the "Register for
InterOp" option does for you) should create you a Type Library (.tlb).
This contains all the COM definitions required.

Use RegTLib.exe on the target machine to "register" the .tlb.

HTH,
Phill W.

Which version(s) of dot.net are present on the target machine?

LS
 
G

Guest

That's a good thought- on target I see 1.1, 1.1 hot fix, and 2.0 via
Add/Remove Programs.
On my dev server I do have 3.0 SP1 and 3.5 Pre-Release that we have been
doing some additional development with. Do you think some of the components I
have used are coming out of the 3.0 framework which is what I should also
install on the target machine?



Lloyd Sheen said:
Brian Kudera said:
Thanks Phill for your advice. I've never read anything before about
registering the tbl file on the target machine. I didn't anticipate
exposing
the tbl file on the target machine either as I do not need our customers
to
know which classes are accessible via COM. In our C++ MFC DLL's that we
currently use in our VB Scripts we did not release the tbl files to our
client machines. Is this something different in the .NET world?

I found the RegTLib.exe on the target machine in the i386 folder and it
appears to have worked okay, however when I try to create the object in a
VbScript it still says it is unable to create the ActiveX component.

=================================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Monitor>cd c:\i386

C:\i386>regtlib c:\ingen\disprog\dis.tlb
Registration of c:\ingen\disprog\dis.tlb successful.

C:\i386>
=================================================


Phill W. said:
Brian Kudera wrote:

I am trying to create one DLL that I can use in vbscripting that has
all of
the common codes and other additional input forms, controls, etc. I
have
DIS.DLL, namespace is DLL, and so far have written four COM Classes
(Project
| Add Item | Com Class) so it automatically generates the GUID's for
each of
my classes. Sample code for one of my classes is below.

On my integration machine I tried dropping the DLL in C:\DIS and:
1. Double clicking on it to register to regsvr32 but get the error that
the
entry point cannot be found
A .Net assembly, even one designed for Interop, is not a valid 32-bit
executable and can't be fed directly into Regsvr32.

2. Using a regasm.exe tool that I have read about for COM classes, but
get
an error saying -Failed to load DIS.DLL because it is not a valid .NET
assembly

That's worrying. Your .Net Assembly is not a valid .Net assembly???

3. Tried using gacutil.exe but am getting an error saying -Failure
adding
assembly to the cache: unknown error.
GacUtil and Regasm are entirely different tools for entirely different
different purposes.

Running regasm on your development machine (which the "Register for
InterOp" option does for you) should create you a Type Library (.tlb).
This contains all the COM definitions required.

Use RegTLib.exe on the target machine to "register" the .tlb.

HTH,
Phill W.

Which version(s) of dot.net are present on the target machine?

LS
 
G

Guest

Ok I think I might be making some progress. The problem with using Regasm
was that I was using the regasm from the 1.0 framework folder. After
switching to the Regasm.exe in the 2.0 framework folder it says it registered
successfully.

I'm still having some issues creating and using one of the classes in my DLL
but I'll post more detail later.

I do have one other question right now- is there any way that I can automate
the registration of this like Visual Studio does to make it more user
friendly for deployment? If the user double clicks on the DLL I would like it
to automatically search for the appropriate regasm tool in the necessary
directory and make the entries in the registry. Is this possible?

=====================================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Monitor>cd c:\ingen\disprog

C:\INGEN\DISPROG>c:\windows\microsoft.net\framework\v1.1.4322\regasm dis.dll
Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

RegAsm error: Failed to load 'C:\INGEN\DISPROG\dis.dll' because it is not a
vali
d .NET assembly

C:\INGEN\DISPROG>c:\windows\microsoft.net\framework\v2.0.50727\regasm dis.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types registered successfully

C:\INGEN\DISPROG>
=====================================================
 
G

Guest

Finally was able to get it to work. Also had to specify the /codebase option
as my DLL is in a DLL specific path and not in the path of the exe calling it
(wscript.exe or cscript.exe).

The command line I used to register a DLL named DIS.DLL and that exists in
the following directory C:\INGEN\DISPROG\ was:
=====================================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Monitor>cd c:\ingen\disprog

C:\INGEN\DISPROG>c:\windows\microsoft.net\framework\v2.0.50727\regasm
dis.dll /codebase
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types registered successfully

C:\INGEN\DISPROG>
=====================================================


Brian Kudera said:
Ok I think I might be making some progress. The problem with using Regasm
was that I was using the regasm from the 1.0 framework folder. After
switching to the Regasm.exe in the 2.0 framework folder it says it registered
successfully.

I'm still having some issues creating and using one of the classes in my DLL
but I'll post more detail later.

I do have one other question right now- is there any way that I can automate
the registration of this like Visual Studio does to make it more user
friendly for deployment? If the user double clicks on the DLL I would like it
to automatically search for the appropriate regasm tool in the necessary
directory and make the entries in the registry. Is this possible?

=====================================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Monitor>cd c:\ingen\disprog

C:\INGEN\DISPROG>c:\windows\microsoft.net\framework\v1.1.4322\regasm dis.dll
Microsoft (R) .NET Framework Assembly Registration Utility 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

RegAsm error: Failed to load 'C:\INGEN\DISPROG\dis.dll' because it is not a
vali
d .NET assembly

C:\INGEN\DISPROG>c:\windows\microsoft.net\framework\v2.0.50727\regasm dis.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types registered successfully

C:\INGEN\DISPROG>
=====================================================


Phill W. said:
A .Net assembly, even one designed for Interop, is not a valid 32-bit
executable and can't be fed directly into Regsvr32.


That's worrying. Your .Net Assembly is not a valid .Net assembly???

GacUtil and Regasm are entirely different tools for entirely different
different purposes.

Running regasm on your development machine (which the "Register for
InterOp" option does for you) should create you a Type Library (.tlb).
This contains all the COM definitions required.

Use RegTLib.exe on the target machine to "register" the .tlb.

HTH,
Phill W.
 
V

vineet singla

I am trying to register a Visual c++ dll using regasm but it gives an error:-
It is not a valid .NET assembly.
I tried it with both the version of regasm (1.1 and 2.0) but it gives same error on both the versions.
I also tried using regasm but it also gives an error.
When I used GAC to register the dll it gave an error:
"Failure adding assembly to the cache: An attempt was made to load a program with an incorrect format."

Can anyone plz help me out in this??

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
A

Armin Zingler

I am trying to register a Visual c++ dll using regasm but it gives
an error:-
It is not a valid .NET assembly.
I tried it with both the version of regasm (1.1 and 2.0) but it
gives same error on both the versions. I also tried using regasm but
it also gives an error.
When I used GAC to register the dll it gave an error:
"Failure adding assembly to the cache: An attempt was made to load
a program with an incorrect format."

Can anyone plz help me out in this??


You accidently posted to the wrong group and in an existing thread.

It must be a managed assembly to be able to use regasm, or an
ActiveX/COM-DLL that must be used with regsvr32. Maybe you get a better
answer in the right group.


Armin
 

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