Is there a way to make the VB6 IDE unload libraries?

When debugging a VB6 application, I noticed that the VB6 IDE supports loading any libraries, if they were used when debugging the application. The library remains loaded between debugging sessions. This gets in the way of my debugging because unfortunately one of our libraries (written in delphi) stores state in globals and has significant initialization / termination logic.

Simplified example of a problem: I have one foo.dll

with a counter inside it. I access this counter with the following declarations in VB6:

Public Declare Function GetCounter Lib "foo.dll" () As Long
Public Declare Function IncrementCounter Lib "foo.dll" () As Long

      

The problem in this case is that the counter is not reset when I start a new debug session. I would rather not write application or library logic to account for this "reworked library" state scenario. I want to start my debugging session from scratch.

I am currently forcibly unloading the library by restarting the VB6 IDE. Is there a better way?

<h / "> edit : I played around a bit with calling kernel32.dll functions to unload / reload libraries from the immediate window; this turned out to be just a good way to crash the IDE or cause random behavior. I should have expected that since the IDE is not knows that the original library descriptor has become invalid.

I accepted AngryHacker's answer as I am now convinced that restarting vb6.exe is the only way to start a VB6 debug session with a completely clean list.

+2


source to share


2 answers


I struggled with this for years, especially when coding ActiveX DLLs for use with IIS sites.



The only real antidote I've found is to keep the library loaded in a separate VB6 instance (assuming you have control over the source). Thus, you can simply click the Stop button on the toolbar and the library will no longer be loaded.

+1


source


There are several things you should look at:



  • Make sure you remove any class references by setting local or global variables = nothing when your application exits.
  • When debugging, NEVER press the end / stop debugging button. It just pulls the rug out of the code and can sometimes leave things in memory.
  • Do not use the End command in the application exit code (see point # 2).
0


source







All Articles