Solved

Error using VB6 Custom DLLs when creating references

Posted on 2011-02-17
3
712 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 500 total points
ID: 34930488
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
ID: 34930729
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
ID: 34930824
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 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