 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alan Bellingham Guest
|
Posted: Mon Jul 25, 2005 11:02 am Post subject: How do I build a truly singleton COM server serving multiple |
|
|
I have an out-of-process EXE server designed to run as a single instance
server.
(Yes, I know, singletons bad. Except that in this case, it truly
models a singleton resource. In this case, it's a specialised printer
queue manager, one queue per available printer, one manager for the
whole lot. The manager is the unavoidable singleton.)
This server should run as a singleton for the entire system. In fact,
it's not. Any number of COM instances may be started by user programs,
or any number of COM instances may be started by ISAPI, and all is fine.
But if both ISAPI and a user program attempt to instantiate COM objects,
then multiple instances of the COM server are started. (I can tell this,
because I have a Mutex that prevents multiple instances running, and
this mutex is indeed preventing a second instance running in this case.)
So, how do I serve both a web server (running as a service) and a user
program with a single instance of a COM server?
Do I have to build it as a service?
Alan Bellingham
--
ACCU Conference 2006 - 19-22 April, Randolph Hotel, Oxford, UK
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Jul 25, 2005 4:29 pm Post subject: Re: How do I build a truly singleton COM server serving mult |
|
|
"Alan Bellingham" <alanb (AT) episys (DOT) com> wrote
| Quote: | Yes, I know, singletons bad.
|
Says who?
| Quote: | This server should run as a singleton for the entire system. In fact,
it's not. Any number of COM instances may be started by user
programs, or any number of COM instances may be started by ISAPI,
and all is fine.
|
Yes, that is fine.
| Quote: | But if both ISAPI and a user program attempt to instantiate COM
objects, then multiple instances of the COM server are started.
(I can tell this, because I have a Mutex that prevents multiple instances
running, and this mutex is indeed preventing a second instance running
in this case.)
|
If you mean the actual EXE is being executed multiple times, then it sounds
like you did not set up the EXE properly in the first place. What are the
EXACT steps you took to design the EXE and its settings?
| Quote: | Do I have to build it as a service?
|
I would suggest that anyway.
Gambit
|
|
| Back to top |
|
 |
Alan Bellingham Guest
|
Posted: Mon Jul 25, 2005 5:28 pm Post subject: Re: How do I build a truly singleton COM server serving mult |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote:
| Quote: | "Alan Bellingham" <alanb (AT) episys (DOT) com> wrote in message
Yes, I know, singletons bad.
Says who?
|
Quite a lot of design commentators. Actually, it's not quite the 'GOTO
considered Harmful' of the Patterns world, but it's close. There are
times when singletons are the correct solution, just fewer than they
actually get used for.
But this is beside the point.
| Quote: | But if both ISAPI and a user program attempt to instantiate COM
objects, then multiple instances of the COM server are started.
(I can tell this, because I have a Mutex that prevents multiple instances
running, and this mutex is indeed preventing a second instance running
in this case.)
If you mean the actual EXE is being executed multiple times, then it sounds
like you did not set up the EXE properly in the first place. What are the
EXACT steps you took to design the EXE and its settings?
|
Indeed, the EXE is getting executed multiple times and indeed, this is
not what is wanted.
As to the steps to design the EXE and its settings ... well, once upon a
time back in 1991 ...
The design history is a real case of bolting code on here, ripping it
out there, and so on. In this case, what was once a GUI program has now
had all the UI ripped off it (and turned into a different program), and
COM interfaces added instead. It works very nicely, excluding the
problem in question. Implementation was achieved by wizard building a
bare EXE COM server (in Visual C++ 6), and then taking the relevant
parts and pasting them into the existing code.
Ah, it's built using ATL, if that may make a difference, with a
CComModule descendant. (I've had very bad experiences with the BCB3/5
VCL com support.)
Do you know of any suitable skeleton example that I could rip apart and
try, rather than try to produce a <50 line example? Either that, or any
on-line tutorial or previous discussion of similar issues?
(Yes, I've tried Googling.)
| Quote: | Do I have to build it as a service?
I would suggest that anyway.
|
Ah. I was hoping to avoid having to do that, though I also do suspect it
would make the problem go away.
Alan Bellingham
--
ACCU Conference 2006 - 19-22 April, Randolph Hotel, Oxford, UK
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Jul 25, 2005 8:07 pm Post subject: Re: How do I build a truly singleton COM server serving mult |
|
|
"Alan Bellingham" <alanb (AT) episys (DOT) com> wrote
| Quote: | As to the steps to design the EXE and its settings ... well, once upon a
time back in 1991 ...
|
I don't need the whole history. I just wanted you to explain, in detail,
everything you did after "File | New" to begin the COM project.
| Quote: | Implementation was achieved by wizard building a bare EXE COM
server (in Visual C++ 6), and then taking the relevant parts and pasting
them into the existing code.
|
Why did you not use BCB's own wizards to create a COM project? You should
have. You are likely missing some compiler/linker options for the EXE.
Create a new EXE using BCB's wizard, then use BCB's wizards to add a Type
Library and an Automation Object to the project. Then go into the Project
Options and set up the ATL options as needed.
| Quote: | I've had very bad experiences with the BCB3/5 VCL com support.
|
What kind of problems?
| Quote: | Ah. I was hoping to avoid having to do that
|
Why?
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|