Solved

Error using VB6 Custom DLLs when creating references

Posted on 2011-02-17
3
694 Views
Last Modified: 2012-08-14
I have created two VB6 SP6 custom DLLs.  BOTH DLLS reference two classes, cPoint and cPoints.

In the code below, Calling Sub CreateShell, the oPoints1 and oPoint objects function correctly and are instantiated against ShellPoints1 classes with the new oPoint = {0,0,0}, then changing to the new values later works too.

Next I am Calling Sub CreateSubShell, the SET oDP = oPoints1 reference works, but the code fails on oPoint.pt3D = oDP('p1").pt3D.  Error 430 - class automation error

In the watch window, oDP("p1").pt3D have values as set in the previous SUB while oPoint = nothing in the watch, but should = {0,0,0} after being instantiated.  No error on the instantiation, just during the set = line.

That said ... can a single project reference two different DLLs that have the same class names?  IF NOT, where could I find information regarding how to use DLLs properly?  Google and the EE search were fairly useless researching this.
Option Explicit
'Custom DLL References'
Dim oPoints1 As New ShellPoints1.cPoints
Dim oPoints2 As New ShellPoints1.cPoints

Private Sub CreateShell()
    'Custom DLL References'
    Dim oPoint As New ShellPoints1.cPoint

    oPoint.pt3D = MakePoint(15#, 280#, 10#)
    oPoints1.Add oPoint, "p1"

    Call CreateSubShell
End Sub

Private Sub CreateSubShell()
    'Custom DLL References'
    Dim oDP As ShellPoints1.cPoints
    Set oDP = oPoints1

    Dim oSDP As ShellPoints2.cPoints
    Dim oPoint As New ShellPoints2.cPoint
    
    oPoint.pt3D = oDP("p1").pt3D
    oSDP.Add oPoint, "pRake1"
End Sub

Open in new window

0
Comment
Question by:bsardeson
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 500 total points
Comment Utility
Yes, you can reference two DLLs that contain matching class names.  By including the Project Name with the class name (as you are doing) will keep the classes distinct.  When your DLLs contain distinct class names, you do not have to include the DLLs project name to access the class.

As for Automation Error, that occurs when you either attempt to access a class or class member that is not public, or does not exist.  It can also occur if you recompile your DLLs without maintaining Binary Compatability.

When you reference a VB DLL, you don't REALLY access it by project name, you access it by GUID.  When you have binary compatibility turned on, each time you rebuild the DLL, the GUID will remain the same, and the project that references the DLL will still find it.  But if you break binary compatability by changing the interface of the DLL, or simply don't have binary compatability turned on in the "Component" tab of the DLLs project properties, you will create a new GUID for the DLL, losing the previous GUID the other project references.

So from what I can make out from your code sample and statements, it looks like ShellPoints2 DLL is either incorrectly referenced (i.e. can't find its GUID), or the instance you are referencing does not have a "pt3D" member for its cPoint class... or oDP("p1").pt3D is not valid for ShellPoints1 DLL.
0
 
LVL 1

Author Closing Comment

by:bsardeson
Comment Utility
The Binary Compatibility was an issue however, I had further problems, so I have just reverted to having multiple instances of a single custom dll, which the AutoCAD VBA 5 seeme to appreciate better, the code also processes nearly 100% faster using the singular DLL.

Thanks!
0
 
LVL 1

Author Comment

by:bsardeson
Comment Utility
To extend HooKooDooKu explanation:
While I actually had binary compatability so to speak when I compiled in the VB6 IDE, I didn't while referencing in the VBA IDE.  Both projects were referencing the same dll name, not each projects dll name:

ShellPoint1.dll binary compat with ShellPoint1.dll
ShellPoint2.dll binary compat with ShellPoint1.dll

Therefore the Error 430 appeared because these Statements were EQUAL ... whoops!  
    Dim oPoint As New ShellPoints1.cPoint =  Dim oPoint As New ShellPoints2.cPoint

I was actually attempting to assign the cPoint oDP("p1").pt3D  to the same memory space with this statement, oPoint.pt3D = oDP("p1").pt3D,  in the second subroutine.

And my solution code using a single custom dll with multiple references:

 
Option Explicit
'Custom DLL References'
Dim oPoints1 As New ShellPoints1.cPoints
Dim oPoints2 As New ShellPoints1.cPoints
Dim oPoints3 As New ShellPoints1.cPoints
Dim oPoints4 As New ShellPoints1.cPoints
Dim oPoints5 As New ShellPoints1.cPoints

Private Sub CreateShell()
    'Custom DLL References'
    Dim oPoint As New ShellPoints1.cPoint

    oPoint.pt3D = MakePoint(15#, 280#, 10#)
    oPoints1.Add oPoint, "p1"

    Call CreateSubShell
End Sub

Private Sub CreateSubShell()
    'Custom DLL References'
    Dim oDP As ShellPoints1.cPoints
    Set oDP = oPoints1

    Dim oSDP As ShellPoints1.cPoints, oSDP1 As ShellPoints1.cPoints
    Dim oSDP2 As ShellPoints1.cPoints, oSDP3 As ShellPoints1.cPoints

    Set oSDP = oPoints2: Set oSDP1 = oPoints3: Set oSDP2 = oPoints4: Set oSDP3 = oPoints5:
    
    Dim oPoint As New ShellPoints1.cPoint
    
    oPoint.pt3D = oDP("p1").pt3D
    oSDP.Add oPoint, "p1": Set oPoint = New ShellPoints1.cPoint

    oPoint.pt3D = oSDP("p1").pt3D
    oSDP1.Add oPoint, "p1": Set oPoint = New ShellPoints1.cPoint

    oPoint.pt3D = oSDP1("p1").pt3D
    oSDP2.Add oPoint, "p1": Set oPoint = New ShellPoints1.cPoint

    oPoint.pt3D = oSDP2("p1").pt3D
    oSDP3.Add oPoint, "p1": Set oPoint = New ShellPoints1.cPoint

    oPoint.pt3D = oSDP3("p1").pt3D
    oSDP4.Add oPoint, "p1": Set oPoint = New ShellPoints1.cPoint
End Sub

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now