Unload a COM control when working in VB6 IDE
Part of my everyday work is maintaining and extending legacy VB6 applications. A common engine is written in C/C++ and VB6 uses these functions in order to improve performance.
When it comes to asynchronous programming, a C interface is not enough and we rely on COM controls to fire events to VB6.
My problem is that when I register the control in VB6, VB loads this control in memory and does not unload it until I quit the VB6 IDE. As the control is loaded the whole time, I am unable to recompile it in VC6, because the DLL file is locked.
A solution I found is not to enable the control in VB but use the CreateObject() with the full name of my control. The problem then is that I must declare my control as an Object because VB6 knows nothing of the interface I am using and I do not have access to IntelliSense, which is a pain.
Any idea how I can tell VB6 to unload controls after quitting the application or directly in the IDE ?
I'm pretty sure there's no good way to force VB6 to unload the control.
Here's what I do... instead of running Visual C and Visual Basic side-by-side, run VB6 under VC :
- Load up VC
- Open the project containing your COM objects
- Edit, change, etc.
- In VC, set the Output Executable to be VB6.EXE with appropriate command-line arguments to load the VB6 workspace
- Now just hit F5 to launch the VB6 IDE and load your VB6 project
- When you want to change the COM code again, exit VB6.EXE, make your changes, and hit F5 again. As long as you save your workspace VB6 will remember what windows you had open and all your project settings.
Advantages of this method:
- You can set breakpoints in the COM object and debug it using a full source debugger
- You can happily debug in C and VB at the same time
- Whenever VB6 is running it always has the latest version of the COM DLLs