duplicating a file-mapping object between 2 processes

Giganews Newsgroups
Subject: duplicating a file-mapping object between 2 processes
Posted by:  András Lukács (lukacsandr…@aol.com)
Date: Mon, 04 Sep 2006


I have a problem duplicating the handle to a file-mapping object and
using it in a different process. I do the following (WinXP Pro):

- create the FMO to be shared in a Win service
- in another process, I get a handle to that process using OpenProcess()
OpenProcess() fails -- I guess that's the problem)
- send the handle to the service
- the service gets a new handle to the FMO using OpenFileMapping()
- the service duplicates the new FMO handle using DuplicateHandle(),
passing the process handle created by OpenProcess() as the
hTargetProcessHandle -- *FAILS* with "invalid handle"
- the service sends the duplicated FMO handle to the other process

The service is a Delphi TService() object, the other process is a Delphi
console app. First, I tried simply getting a new handle to the FMO of
the service using OpenFileMapping() in the other process (by name) but
it failed with "access denied".

Is what I am doing theoretically wrong somewhere or will I need to do
some security stuff to the FMO object first because it is created in a
service? (just a guess)

Both programs run under the same user account.

Thanks for ideas,