• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

ActiveX component to stay resident

How can I set the properties of an ActiveX component to stay resident, ie I want one exe to start it and it show a form, the form remains when the referencing exe closes, then another referencing exe starts and invokes a method to close the ActiveX form.

I'm sure I done this before?
0
nickwoolley
Asked:
nickwoolley
  • 6
  • 6
  • 3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
activeX exe is what you need, where you will need to implement the GetObject() support:
http://www.devx.com/premier/mgznarch/vbpj/1997/08aug97/bbelt.pdf
0
 
nickwoolleyAuthor Commented:
I think it is the 'Unattended Execution' property which needs to be checked, however it's greyed out in my project (it's a copy of another project as a base). I think the fact it is greyed out must be a bug in VB.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
unattended execution is only to avoid that blocking forms, msgboxes etc can be displayed/used in your applications.
The fact that it's greyed out is either
* you don't have the enterprise edition
* the type of project is either Standard-Exe or ActiveX Control. Thus you would need ActiveX-Exe or ActiveX-DLL for this to be available

Cheers
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
nickwoolleyAuthor Commented:
When I start a new project it allows me to check 'Unattended Execution' but forms cannot be added to the project. I am using an ActiveX.exe, but as soon as the referencing program closes the componant dissappears, whereas I want it to stay resident so another program can reference the same instance.
0
 
nickwoolleyAuthor Commented:
angellll: from your link I think I have to use the API CoLockObjectExternal
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
nickwoolley, you cannot use the 'Unattended Execution' for your project, as it explicitely says in the docs that this option prohibits the usage of forms.
Anyway, for your needs you don't "want" this option to be checked, you simply need some code to support this.

In short, you need the form to stay alive, even if the referencing application exists. To do so you simply try to get the main form running and only quit when either the applications's quit function is started, or when the main form's queryunload function is called with Unloadmode = vbAppWindows

CHeers
0
 
Julian_KCommented:
Hi.
The problem can be solved easily:

1. From the Project/Properties/General:
Select "Startup Object: Sub Main"

2. Create a .BAS module in your ActiveX EXE, with a sub Main. Something like:
--------------------------------------
public X as myForm1

Public sub Main
    Set X = New myForm1
    Load X
End Sub

---------------------------------------
3.Create a Class Module with 2 methods:
---------------------------------------
Public Sub DisplayForm
   X.Show
End Sub

Public Sub HideForm
   X.Hide
end Sub

4. In Your Client Application (for ActiveX EXE becomes Server), create an Instance of this class module like:

Set MyObj = new ProjectServer.Class1
Class1.DisplayForm
Class1.HideForm

ect...

wishing luck
Julian
0
 
Julian_KCommented:
Oh, Include one more method in the class: Something like

Public sub DestroyServ
   UNLOAD X
   Set X=Nothing
end sub

Or else the ActiveX exe will stay resident in memory until you shut it down with (Ctrl-Alt-Del) ;)
0
 
nickwoolleyAuthor Commented:
Julian: I'm not managing to get a reference to the component once the 1st exe has closed.
0
 
Julian_KCommented:
Let me ask If I get your question right. You say:

"How can I set the properties of an ActiveX component to stay resident, ie I want one exe to start it
and it show a form, the form remains when the referencing exe closes, then another referencing exe starts
and invokes a method to close the ActiveX form."

I tested the example I have provided right now, And It works.

I mean, In your FIRST CLIENT EXE (Referencing EXE, as you call it), execute just the metod "DisplayForm" of the CLASS1. Then Set CLASS1=NOTHING, and Close The Client.

The class goes to nothing, but the ACTIVEX EXE SERVER stays resident in memory, and the displayed form also stays visible.

Then Start Another Client App (second referencing App), create new CLASS1, and execute "HIDEFORM" method, and then Call "DESTROYSERV" method, WITHOUT calling "DISPLAYFORM" before it. The second Referencing app will hide the form and will destroy the server.

If you followed the steps I provided, It all should be working fine: the first Client App will display the Server's form, and the second App will hide it.
--------------------------------------------------
Don't forget to put "SUB MAIN" as startup object in "Project/Properties"
--------------------------------------------------
0
 
Julian_KCommented:
One more thing I forgot:
In "Project/Properties/General" :
Set Threading model to "Thread Pool: 1 threads"
0
 
nickwoolleyAuthor Commented:
Julian: Think I've got it working now, I had some variables in my class whereas they should have been at module level. I did something similar a while ago with DB connection objects held in an ActiveX componant; it seems that while a componant holds an internal reference to an object then it does not close, and is therefore resident ready to be referenced by other exe's.

Will be back to award points once I've confirmed it's working.
0
 
Julian_KCommented:
That's right.
So, If you want to store all the objects/properties/values in all the objects on the server without loosing them, just create one BIG Object that holds them all, declare it in a module level, and create one small object (pipe) that references to the big one in the module.
The client should create this "pipe" and from it will get a reference to the BIG ONE, and from it - to all other objects.
0
 
nickwoolleyAuthor Commented:
Angellll: Thanks for your help, however I have used Julian's method.

Julian: Thats how I shared my DB connections before. I think what threw me was that I had a form unload command hiding in the class terminate method of my copy project. Presumably it would also work if I didn't set a ref to the form via an object, but just loaded the form direct?
0
 
Julian_KCommented:
Hmmm... not sure I got your question right...
if you mean that...
Of course, there is no problem if you load the form direcly and display it on startup of the AX-EXE. The ref to the form via an object is used just to control it from the Client App, and to be able to terminate the AX-EXE at the end (when it is needed).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now