Image of Navigational Map linked to Home / Contents / Search "Error Loading DLL"... a solution!

by George Raudabaugh - Infomentum
Image of Line Break

Editor's Note : This article is extracted from two posts on the Active Server Pages newsgroup by George Raudabaugh of Infomentum. It's a life saver for many developers!

Check out Infomentum for some handy server-side ActiveX controls, too...

 

This error has plagued VB5 server-side developers since SP2 was released. It relates to the way SP2 handles collections...

There is a huge gap with collections and the VB5 SP2 .dll file. If you don't wrap a a collection class around all collections you will get the "Cannot Load .DLL" problem. And even if you create the ActiveX DLL using SP2 you still get the problem.

This was a pain to diagnose because we saw the member that was a collection fire but then immediately die (this is fun to diagnose under ASP). It only took us 2 months ;).

Really it was when we shipped our product out and some folks started reporting this problem. We couldn't reproduce it (we were running under SP0 of VB). Finally, we asked one of the customers to send us their NT registry, and by mistake, clicked on it (it was from a German user).

After reinstalling NT after that episode, plus new versions of the software, we managed to get the MSVBVM50.DLL from SP2 on the system somehow (we think it was an upgrade to our fax software). Bang, it fell down and we managed to track the problem down.

Ouch, that hurts.

The fix is to wrap a collection class around the collection.

Stub code:

 Option Explicit
 Private m_cList As Collection

 'Add
 'Purpose     - Add to list
 'Inputs      - (String)  sKey
 '            - (Variant) vItem

 Public Sub Add(ByVal sKey As String, vItem As Variant)
   m_cList.Add vItem, sKey
 End Sub

 'Remove
 'Purpose     - Remove from list
 'Inputs      - (String)  sKey

 Public Sub Remove(sKey As String)
   m_cList.Remove sKey
 End Sub

 Public Property Get Count() As Long
   Count = m_cList.Count
 End Property

 Public Property Get Item(sKey As String) As Variant
   On Error Resume Next
   If m_cList.Count > 0 Then
     If IsObject(m_cList(sKey)) Then
       Set Item = m_cList(sKey)
     Else
       Item = m_cList(sKey)
     End If
   End If
 End Property

 Public Property Get NewEnum() As IUnknown
   On Error Resume Next
   Set NewEnum = m_cList.[_NewEnum]
 End Property

 Private Sub Class_Initialize()
   On Error Resume Next
   Set m_cList = New Collection
 End Sub

 Private Sub Class_Terminate()
   On Error Resume Next
   Set m_cList = Nothing
 End Sub
Also, in Visual Basic, under the Tools -> Procedure Attributes dialog Advanced settings, mark the Item methods Procedure ID as default and the NewEnum procedure Id as -4 (you will need to type this in manually). Upgrading to SP2 (or SP3) of VB does not fix this problem. However, Class Builder 1.2 generates the stub code for free.



Written by: George Raudabaugh
January '98

Image of Arrow linked to Previous Article Image of Arrow linked to Next Article
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]