Solved

ActiveX component to stay resident

Posted on 2002-06-14
15
386 Views
Last Modified: 2013-11-26
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
Comment
Question by:nickwoolley
  • 6
  • 6
  • 3
15 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
 

Author Comment

by:nickwoolley
Comment Utility
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
 

Author Comment

by:nickwoolley
Comment Utility
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
 

Author Comment

by:nickwoolley
Comment Utility
angellll: from your link I think I have to use the API CoLockObjectExternal
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
 
LVL 5

Accepted Solution

by:
Julian_K earned 100 total points
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 5

Expert Comment

by:Julian_K
Comment Utility
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
 

Author Comment

by:nickwoolley
Comment Utility
Julian: I'm not managing to get a reference to the component once the 1st exe has closed.
0
 
LVL 5

Expert Comment

by:Julian_K
Comment Utility
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
 
LVL 5

Expert Comment

by:Julian_K
Comment Utility
One more thing I forgot:
In "Project/Properties/General" :
Set Threading model to "Thread Pool: 1 threads"
0
 

Author Comment

by:nickwoolley
Comment Utility
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
 
LVL 5

Expert Comment

by:Julian_K
Comment Utility
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
 

Author Comment

by:nickwoolley
Comment Utility
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
 
LVL 5

Expert Comment

by:Julian_K
Comment Utility
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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now