p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

comdeveloper thread: AW: general COM-question


Message #1 by "Marko Kirchhoff" <Marko.Kirchhoff@s...> on Tue, 20 Feb 2001 21:02:48 +0100
use a named semaphore.



marko



-----Ursprüngliche Nachricht-----

Von: Jurgen Lisabeth [mailto:jurgenls@s...]

Gesendet: Dienstag, 20. Februar 2001 16:08

An: COMdeveloper

Betreff: general COM-question





I'm writing an COM-object in a in-process server (dll).

One of its methods is 'Claim'. Purpose of 'Claim' : allow exclusive access

to a device to the application

who first called 'Claim' on the object. In this method I set a boolean to

TRUE (private member of object)

so I know the first application has claimed it.



I assumed (based on a little COM-knowledge) that when I called the Claim-

method in a second application

it wouldn't be impossible to Claim it (since boolean = TRUE). Apparently

I'm mistaken since it's possible

to claim the device in a second application (boolean = false).

How does COM handle this situation (what the correct way of working here

by COM) and how must I handle

it?

Don't I receive always a same pointer to the requested interface?



Do I have to use shared memory to solve this?



Please Help. Thanks














Message #2 by Holger Thiele <HThiele@D...> on Wed, 21 Feb 2001 09:11:44 +0100
Hi Jurgen,



an in-process COM server is just a dll, so

your last question hits it squarely on the head:

You will have to use shared memory for in-process

servers to manage a state shared across multiple

processes.

However, the idiom for solving this problem is

to use an out-of-proc server. Many people implement

a singleton object for this kind of stuff, since singletons

are supported by the ATL. This is not a recommended

procedure, though, since it violates some of the COM

rules (especially instantiation and apartments).

If performance permits, i'd use an out-of-proc server

that just manages state across multiple COM objects.



Cheers,



Holger





-----Ursprungliche Nachricht-----

Von: Jurgen Lisabeth [mailto:jurgenls@s...]

Gesendet: Dienstag, 20. Februar 2001 17:08

An: COMdeveloper

Betreff: general COM-question





I'm writing an COM-object in a in-process server (dll). 

One of its methods is 'Claim'. Purpose of 'Claim' : allow exclusive access 

to a device to the application 

who first called 'Claim' on the object. In this method I set a boolean to 

TRUE (private member of object) 

so I know the first application has claimed it.



I assumed (based on a little COM-knowledge) that when I called the Claim-

method in a second application 

it wouldn't be impossible to Claim it (since boolean = TRUE). Apparently 

I'm mistaken since it's possible 

to claim the device in a second application (boolean = false). 

How does COM handle this situation (what the correct way of working here 

by COM) and how must I handle 

it?

Don't I receive always a same pointer to the requested interface?



Do I have to use shared memory to solve this?



Please Help. Thanks












Message #3 by "Jurgen Lisabeth" <jurgenls@s...> on Wed, 21 Feb 2001 14:59:35
Holger,



I'm creating an object following the OPOS-rules (maybe you already heard 

from this MicroSoft-standard for Point of Sales devices). OPOS recommends 

to use a in-process server instead of an out-of-proc server.

I think I need to use shared memory here and also make use of some 

synchronization object (mutex) to inform the second application if the 

device is claimed (signaled) or not (nonsignaled).



What do you mean by 'a singleton object' ?



Thanks 

Jurgen


  Return to Index