Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Error using VB6 Custom DLLs when creating references

Posted on 2011-02-17
3
Medium Priority
?
716 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

618 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