Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveX exe server issue when closing app 1

Status
Not open for further replies.

newora

Programmer
Joined
Aug 19, 2003
Messages
133
Location
GB
Could someone please help me with an issue regarding ActiveX out of process servers and specificaly how to tidy up, or dispose of them when they are nolonger required.

I have created an Active X exe project in VB6 and this seems to work OK (I used to be able to step into it and debug it using another instance of VB, but I can no-longer do that for some reason).

Anyway my main application creates an instance of the ActiveX server via a menu option and then calls one of it's public methods i.e.

public sub menu_click1
dim machine_reporting as clsmachinereport

machine_reporting = new clsmachinereport
machine_reporting.show_report
end sub

This works OK and obviously creates an instance of the Active X server and shows a report form (also exe can be seen in task manager).

However if I end my main application , the active X server still stays active/running, presumably because it is running in it's own process space.

In point of fact the customer quite likes this effect, but I would like to be able to kill the instance of the Active X server when my main application program ends.

I thought that from reading the Microsoft documentation that this would happen automatically, as the server keeps a count of the number of clients it is communicating with.

I am obviously missing something somwehere, so if someone could please enlighten me, it would be much appreciated.

Thanks
 
First question: is your activex exe singluse or multiuse? Second question: are you showing the report form in the server or the client?

Bob
 
The Active X exe is single use, as I have a crystal report 6 component on it, which only allows single use.

The report form (for entry of start and end dates etc.) is being shown in the server.
 
Aha. Here's a quote from
Out-of-Process Component Shut Down
An out-of-process component written with Visual Basic will shut down when:

The component has no forms loaded.
A loaded form will keep your component running past the point at which all references have been released. Forms should be unloaded when the object that created them terminates.

No out-of-process client applications are holding references to the components public objects.
Internal references to public objects will not keep a component running if clients have released all their references. Neither will references held by an in-process component the out-of-process component is using.

No code in the components modules is currently executing, or in the calls list waiting to be executed.


The component is not in the process of being started in response to a client applications request for an object.

I asked about single use to see if maybe there were client references to the component your program isn't aware of. Since you're running singleuse, that's unlikely, given that there's a different copy of the server program for each client instance.

I asked about forms because if the form's in the server it won't shut down until you unload the form. It would seem that this is the reason that your program stays open. If you want to control the shutting down of the ActiveX EXE from the client, create a Quit method or some such in the server, and unload the form in it. Call the quit method from the client, set the object to nothing, and you're done.

HTH

Bob
 
Hi Bob,

Thanks very much for the reply.

I actually did create a quit method on the active X server to do exactly that (unload the form) but it did not work for some reason and so I assumed that it was something more basic at fault.

In the quit menu option of my main application I placed code like this, but I kept getting erorr 41 object required when trying to call the destroy_report method. I got the same error when I made machine_reporting a global !! :-

private sub exit_app
dim machine_reporting as clsmachinereport

machine_reporting = new clsmachinereport
machine_reporting.destroy_report

end sub

In my Active X server I have a public method:-

Public Sub destroy_report()
Unload frmmachine_report
End Sub



Any furtherhelp would be greatly apreciated and thanks again.
 
I found the problem with the object required error - in the form_destroy method of the Active X server I had spelt the name of the form incorrectly. DOH.

Another quick question then please, how can I turn this component into a standalone, runnable exe as well as an Active X exe server - like word , Excel etc. I have read the VB Active X help but it doe snot seem to mention anything.

Thanks again?
 
1. Create a new folder. Put all the forms and modules and stuff you need from your ActiveX exe there.
2. Go into VB, create a new standard exe project.
3. Remove Form1. Add in all the files you copied in number 1 above.
4. Set your startup object (a form or Sub Main).
5. Set project properties, save as you would any new project.

That should do it. Of course, you're maintaining code in 2 places, assuming you're still using the ActiveX exe. To help with this, consider putting routines that they both use into an ActiveX Dll, and having both exes point to it.

HTH

Bob
 
Great Thanks for that Bob. As you state, this method means that you are effectively maintaining 2 sets of source code and also have 2 exe files.

It is not just possible to have the 1 exe - is this not now Word Functions?
 
Well, no, not exactly. Word has an exe, and also a dll that other exe's can use to implement word functionality. In that case, there are 2 exe's too, aren't there?

You could put most of your functionality into a dll, and call that dll from both of your exe's though, which is why I mentioned that. Then you wouldn't have 2 sets of source code. Your dll could expose the form, and so you could then show the form from both exe's, and keep the form code in one place.

A good example would be cards.dll, which is used both by sol.exe and freecell.exe.

HTH

Bob
 
Another quick question then please, how can I turn this component into a standalone, runnable exe as well as an Active X exe server - like word , Excel etc. I have read the VB Active X help but it doe snot seem to mention anything.

It can be done quite simply, you need to check the App.StartMode Property which has 2 values
VbSModeAutomation (= 1) and shows that the exe has been started as a COM Object and VbSModeStandAlone (=0)

You then need to code appropriately

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Thanks a lot for your input guys - it has helped make this a lot clearer.
 
There are other properties that you have to set as well. For example, you have to set a startup object if you use a standard exe, since you're not instantiating the object from another one.

Bob
 
For example, you have to set a startup object


Good catch - I forgot that one

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Ok, I did some fooling around. Newora, you might want to check this link: Somebody shows how an ActiveX exe can work either in standalone mode or as a component. Apparently, you don't need two exe's; the ActiveX exe will show the form to a client if it is already running standalone, and run invisibly if the client starts it.

The link doesn't really go into SingleUse or MultiUse. Aside from performance considerations, keep in mind that all clients share the same global data in the latter, and have their own copies with the former. Also, SingleUse is more fault-tolerant, in that one client's instance can go down without affecting the other clients.

If you work through this, please let us know the gory details.

Thanks,

Bob
 
Absolutely excellent - thanks Bob. I have to get a project out of the way by the end of the month and after that, when I have time, I will have a closer look.

Thanks again for your insight into this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top