VB6: Problem in Compiling an ActiveX ocx & ActiveX exe having circular ref.

Posted on 2006-04-27
Last Modified: 2008-03-03
I have a problem in compiling two VB projects that was delivered to us by a third party.
Here are the details:
Windows 2000 Server service pack 4
VB6 service pack 5

 a. APScroll.vbp --> compiles to an ocx (AP.ocx)
 b. DistroWindows.vbp  --> compiles to an ActiveX exe (DistroWindows.exe)

The two projects have a circular reference, in that
1. APScroll.vbp creates a class CostDist, declared in DistrowWindows.exe and passes the reference of WFXShellUC to CostDist.
2. DistroWindows.vbp refers to a UserControl (Name: WFXShellUC) that is defined in APScroll.vbp

   Here's the code in the user control WFXShellUC:
   Public WithEvents d As CostDist.clsCostDistDlg
       Set d = New CostDist.clsCostDistDlg
        With d
            Set .ctlRef = Me
            MsgBox ("Set Control Reference")
            MsgBox ("Initialized")
        End With

Here is the procedure I followed:
1. compile DistroWindows.exe
      (refer to an existing ap.ocx)
2. Add project references to DistroWindows.exe compiled in step 1 in APScroll.vbp and compile APScroll.vbp to ap.ocx.
3. The compile in step2 fails with the link error saying "cannot replace object ap.ocx)
    I guess  the reason being DistroWindows.exe (added to project references of APScroll) intern refers to AP.ocx that we are trying to replace.

Any help in getting these two projects compiled is appreciated.
If needed I can email the two projects and dependent files.

Question by:uscold
    LVL 142

    Accepted Solution

    you cannot have circulare reference in projects, you have to use a third project as intermediate through which you make the calls, or the third project contains the Interface classes which the other 2 project classes implement respectively and call respectively.
    In case of OCX, which probably has some events, the RefProject should have a OcxEventSink class, which the OCX has as property object, which actually sends the events out.

    RefProject (ActiveXDLL), contains the following classes (sample):

    The APScroll project:
      OP.ocx -> implement IClassA, and has a property object of type OcxEventA

    The DistroWindows project
      The application class implements IClassB...


    Author Comment

    do u have an example code for this?

    Also the project (compiled versions) are currently running in production.
    This was delivered by a 3rd party who had actually written and installed it in production and it is running fine.
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    no. as I left my previous job where I had such a case, I was (obviously) not allowed to take a copy...
    LVL 26

    Assisted Solution

    use late binding on APScroll.vbp
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    technically, the answer was given (angelIII and EDDYKT), hence, I would say point split

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    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.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 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

    15 Experts available now in Live!

    Get 1:1 Help Now