?
Solved

Accessing a single EXE automation server from VBScript

Posted on 2005-04-07
4
Medium Priority
?
274 Views
Last Modified: 2013-11-20

Is it possible to launch an executeable automation server without the /Automation command line parameter, and then have an external VBScript access the exposed objects from that particular instance of the server?

Basically, I want to have an application that can be launched by the user, which is accessed and manipulated by external VBScripts. I only want one instance of the application to ever be present. If the application doesn't exist, then I want it to be automatically launched by the VBScript. The app should stay open after the VBScript has finished with it.

My current situation is that if I manually run the executable (i.e. without the "/Automation" command line parameter), and then run a VBScript to access the automation objects exposed by the application, it just starts a new instance of the application, rather than using the existing instance.

Secondly, if I run the application WITH the "/Automation" command line parameter, the VBScript is able to access the instance correctly, BUT(!) the application shuts down as soon as the VBScript has finished with it.

It's not a major problem to have to start the app with the automation flag, it's just a bit untidy. Although in which case, I need to know how to stop the app shutting down after it has finished with it.

Ideally, an answer would tell me how to do get what I want without having to use the automation flag at all.

Thanks in advance.

Regards

Andy
0
Comment
Question by:fxnut
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:rcarlan
ID: 13730612
Do you have the source code of the server application?

If you do, you can change it so that:
1. it doesn't require the automation switch
2. it remains active/running if started without the automation switch, even after all clients have released their COM pointers

If you don't have the source code, you are stuck - short of wrapping the existing server in another one that you would have to write and which would act as a broker/manager to the original server. Btw, this solution would have performance issues due to the double marshalling layer involved.

Radu
0
 
LVL 1

Author Comment

by:fxnut
ID: 13730790
Hi Radu,

Yep, I can't believe I didn't think of your first point that you stated! Obvious, yet effective. Thanks :-D

Yes, I do have the source code of the server app. It's just a simple MFC project with Automation enabled on it. The problem I'm having is that when the internal CCmdTarget derived object is finally released by the VBScript, my application quits. I traced this problem down to the override of the OnFinalRelease() function, where it simply calls the base class's implementation of it. It's this function that closes the program. If I comment it out, it works okay and doesn't quit, but I'm a little worried that there may be some resources that remain allocated if I don't call this function from the base class.

Do you know what the OnFinalRelease() function actually does? I'm wondering if I can implement it myself and just leave out the part where my application is forced to close (which, to be honest, seems a little "rude" - what if I had to release my own resources external to the CCmdTarget derived object in my app?).

Do you think it would it be dangerous for me to call the object's CCmdTarget::OnFinalRelease() function manually when I'm about to shut the app down myself?



0
 
LVL 9

Accepted Solution

by:
rcarlan earned 1600 total points
ID: 13731633
CCmdTarget::OnFinalRelease is called on the COM object (represented in an MFC application by a CCmdTarget derived class instance) when the last reference to the object was released by the client.
You are supposed to release associated resources and delete the CCmdTarget object at this stage. If you don't, you're going to leak memory/resources.

The easiest way to conditionally keep your MFC COM server alive is to create/instantiate one of your COM objects right in your server (e.g. at start-up). Then, on close, release this COM object and go through the normal shut-down procedure.

Radu
0
 
LVL 1

Author Comment

by:fxnut
ID: 13734372
Cool, thanks for your help :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

850 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