7

I am tasked with resurrecting a VB6 project and it has been too long since I worked with VB6.

Here is my problem.

Project A is an ActiveX EXE project. Within the same Project Group there is another ActiveX EXE project; Project B. Project B contains clsCommon (clsCommon.cls) that Project A needs to use, as in:

Private clsCommonA as ProjectB.clsCommon 

When I attempt to add Project B's output exe (not the vbp) to Project A's references, I get the error Project 'Project B.vbd' can not be referenced because it's project type is EXE.

Can someone please remind me how to reference classes inside of an EXE? (I am having no trouble with referencing classes in projects in the project group where the output is a ActiveX DLL)

BTW: I assume this is even possible only because some developer 20 years ago evidently had this working.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
davecove
  • 1,001
  • 4
  • 16
  • 36
  • 1
    I always thought from EXE to EXE required using late binding (ie `CreateObject()` calls). Maybe there is another way, I'm interested in the answer. – StayOnTarget Jul 09 '19 at 19:08
  • AFAICR it is possible to use EXE to EXE with early binding. I'm 99% sure that ActiveX EXEs are in the registry and can be added to project references just like any other ActiveX (aka COM) component. An ActiveX EXE is also a type libary. Regarding project groups specifically though, I cannot remember how to add a reference to an ActiveX EXE within a project group. I would have thought you add the VBP file. AFAICR that is how you add a reference to an ActiveX DLL project to another EXE project in the same group. @davecov, what happens if you try to add the VBP? – MarkJ Jul 10 '19 at 11:23
  • @MarkJ thanks for that comment, it jogged my memory. – StayOnTarget Jul 10 '19 at 12:14
  • 1
    Note to other readers --- although the answer I placed below links to a bunch of other questions and their answers share similar elements with this one I didn't actually think the question itself was a duplicate. I didn't find another VB6 question asking how to do this. – StayOnTarget Jul 10 '19 at 12:15

2 Answers2

5

VB6 does not allow you to add a reference to an ActiveX Exe (your ProjectB) from a project (ProjectA) that is loaded into the same IDE (project group). You get the error displayed when you try.

This is because an ActiveX Exe runs as a separate process, which I believe the VB6 IDE isn't capable of doing for separate projects in a group. So while it looks like you are adding the reference to ProjectB exe, since it's in the group, VB6 is actually adding a reference to ProjectB vbp, which isn't supported.

You need to remove ProjectB from your group. Then you'll be able to reference the ProjectB Exe from the ProjectA IDE.

If you need to run ProjectB in the IDE (for debugging or development), then first start VB6 and load ProjectB. Then start a second instance of VB6 and load ProjectA. When you start ProjectB, you'll notice that the reference in ProjectA changes from the ProjectB Exe to the ProjectB vbp (running in the second IDE). Set breakpoints in ProjectB as appropriate, then when you start ProjectA and instantiate ProjectB and make the method calls, you'll be running the ProjectB code in that IDE.

MarkL
  • 1,721
  • 1
  • 11
  • 22
3

(NOTE - I've revised part of this)


As for the VB6 projects inside the group, you should be able to add mutual references to other projects in the group using the usual References window, EXCEPT TO EXE projects.

I tried this with a pair of test EXE / DLL projects, and when I try to add the EXE reference within a group I get an error:

enter image description here

(test1.vbp can not be referenced because it's project type is EXE.)


However I can reference the compiled EXE without issue from the DLL project. This may be your best way forward.

In order to register a compiled EXE, VB6 will do this for you when you compile it, but there was also a manual method which I eventually remembered - you need to run the .EXE itself using the /regserver switch.

Assuming that your .VBP already has the correct entries (basically, a reference line which points to the GUID of the EXE and/or some DLLs and OCX files) once you do this is should automatically find the classes in the EXE when you compile / run.

This is described in detali by several other SO questions so I won't repeat all that:

etc.


If you need to debug into the EXE from the group of DLLs, first make sure all the references are hooked up. Then you should be able to run the EXE project in the IDE, set breakpoints, and run the DLL group separately in another IDE instance and debug between them.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • I decided to go the DLL route and was less than successful. First I deleted all binaries made by both projects. Then I removed the reference to Project B from Project A's vbp file. Then I built Project B as an ActiveX DLL and referenced it again in Project A. I checked that the reference to the DLL was back in Project A's vbp file along with the proper path to the DLL. It was there. Then I tried to build Project B and the line `Private clsCommonA as ProjectB.clsCommon` results in `User-defined type not defined.` – davecove Jul 10 '19 at 17:20
  • 1
    @davecove, I'm not sure how that relates to this answer, which was not advocating building anything but possibly the EXE. It is almost always best to run in group when possible. The error you could could possibly be if binary compatibility is not set on the DLLs - one situation avoided by running in the group. – StayOnTarget Jul 10 '19 at 18:45