Question

A VB6 application is using the Interop Forms Toolkit to work with forms written in .NET. The documentation for the toolkit advises calling a method on the toolkit to advise the toolkit when the VB6 application is shutting down.

The VB6 application uses a Sub Main procedure that loads a splash screen, then displays several modeless forms. When Sub Main completes, the application is still running. How can the application detect that it is shutting down and call the cleanup method on the Toolkit?

Was it helpful?

Solution

In a module (probably the same one that contains Sub Main), create a public sub (e.g AppCleanUp) that will hold your cleanup code.

Add a class to your project (e.g. clsAppCleanup). In this class, add code in the Class_Terminate event handler that calls the sub you created in the previous step.

In a module (probably the same one that contains Sub Main), define a variable of clsAppCleanup.

In Sub Main, instantiate the clsAppCleanup.

When the app is shutting down, The terminate event on the class will cause the cleanup code to run.

OTHER TIPS

Its been a while since I wrote in VB6 but if I remember correctly you can use the Unload event to call your cleanup code (it similar to the closing event in .net). You can also check that there are no other forms in the VB6 app still running

Create a module that contains a FormCount variable. This variable will be shared by all forms in your application. Increment the FormCount variable in every form's Form_Initialize method. Decrement FormCount in every form's Form_Terminate method. When FormCount drops back to 0, you can notify your form toolkit that of the forms have been unloaded.

You won't have to worry about multi-threading issues because VB6 creates single-threaded applications, so one form's Initialize (or Terminate) method will run to completion before any others begin execution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top