Home All Groups Group Topic Archive Search About

Problem Using VB.net Class Library DLL in VBScript

Author
27 Oct 2007 10:20 PM
Brian Kudera
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

Author
29 Oct 2007 1:42 PM
Phill W.
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.
Author
27 Nov 2007 9:42 AM
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
Author
27 Nov 2007 10:08 AM
Armin Zingler
<vineet singla> schrieb
> 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