Solved

ActiveX component to stay resident

Posted on 2002-06-14
15
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 3
15 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7077894
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
ID: 7077901
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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7077907
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:nickwoolley
ID: 7077926
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
ID: 7077936
angellll: from your link I think I have to use the API CoLockObjectExternal
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7077942
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
ID: 7077970
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
 
LVL 5

Expert Comment

by:Julian_K
ID: 7077984
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
ID: 7078052
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
ID: 7078160
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
ID: 7078185
One more thing I forgot:
In "Project/Properties/General" :
Set Threading model to "Thread Pool: 1 threads"
0
 

Author Comment

by:nickwoolley
ID: 7078316
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
ID: 7078352
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
ID: 7078378
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
ID: 7078408
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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