Re: multi-process singleton DLL

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Instead of using IPC, wouldn't it be possible to use DuplicateHandle()
such that ProcessA opens the DLL and gets the original resource
handle, then Process B opens the DLL and gets a DuplicateHandle()?

I'm glad you mentioned the second process. I didn't consider what
would happen to Process B if Process A closed the resource. What about
using the DLL to keep a reference count of all the handles created,
then it could wait for the reference to become 0 before it really
releases the resource. Would that work?

Thanks,
Paul

On Jul 23, 10:47 am, "Ben Voigt [C++ MVP]" <r...@xxxxxxxxxxxxx> wrote:
"PaulH" <paul.h...@xxxxxxxxx> wrote in message

news:1185203158.770652.52140@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I have a DLL that exports a class that allows a program to access a
unique system resource.

At the moment, the DLL is implemented as a singleton such that any
thread in a given process is using the same resource handle.
But, if a second, unrelated process loads the DLL and accesses it,
this process will try to create its own handle to the resource which
fails because it's already in use by the first process.

How do I give the second process access to the handle that's being
used by the first process so that both can query the resource?

Pick an IPC method, any method. Note that to do this cleanly, it is
necessary that a separate process be set up to "own" the true handle,
because if the owning process closes the resource will be released.

Named pipes would probably be a good choice, because the proxy process can
detect abnormal termination of a client.



Thanks,
PaulH


.



Relevant Pages

  • Re: internationalisation
    ... So, for dialogs, we keep all of a projects dialogs in the exe rather than ... separate copies in each language dll. ... It shows you how to build dialogs without resource files. ...
    (microsoft.public.vc.mfc)
  • Re: ? Segregating a Dialogs Code (Particularly Resources)
    ... I typically put all of the common code in a single Dll, ... the projects that need access to the common code. ... Now the problem with my solution is that if one control, ... both resource files and drag the resources over to the new project. ...
    (microsoft.public.vc.mfc)
  • Re: multi-process singleton DLL
    ... creates an IPC server and manages the DLL resource. ... They both interface using this DLL I wrote to take care ... communicate with the IPC server, ... could bind to the protocol driver, the other would get "The requested ...
    (microsoft.public.vc.language)
  • Re: How to write a program with multi-language support but not needed to define "UNICOE"?
    ... Put each resource file with different langauge in different dll. ... standpoint of providing UI in multiple languages, ...
    (microsoft.public.vc.mfc)
  • Re: multi-process singleton DLL
    ... creates an IPC server and manages the DLL resource. ... They both interface using this DLL I wrote to take care ... communicate with the IPC server, ... procedure of opening the protocol driver and binding to it. ...
    (microsoft.public.vc.language)