Link to home
Start Free TrialLog in
Avatar of kfe
kfe

asked on

NT Services & MapViewOfFile handles

Dear experts...

I have written an NTService that I need to 'talk to' from various other applications via a DLL, so my service creates a hidden window that anyone else can send messages to. This all works fine for simple commands that can return their data in 32 bits, but some of the functionality I need to offer requires the two way transfer of character strings.

So, I create and populate a file map in my DLL (using CreateFileMapping), and send a message to my service asking for its Process Id so that I can use DuplicateHandle() to pass the file map across. This works fine when I run the service in the debugger, and also if I run it just as an executable. But when I run it as a service, when the service tries to use MapViewOfFile() using the duplicated handle, it gets a null pointer and GetLastError returns 6  (ERROR_INVALID_HANDLE).

Is there anything strange about how Services run and in particular their process context that might cause this? Are there any other/better ways of achieving a similar result other than having a hidden window?

Any help or ideas much appreciated!

kfe
Avatar of kfe
kfe

ASKER

Edited text of question
Avatar of kfe

ASKER

I've looked further into this, and have discovered that it has nothing to do with file map handles, but that the problem happens in my DLL!

When I try to use duplicate handle I use OpenProcess() to get the handle of the Service's process. but this returns a NULL handle! and GetLastError() gives me 5 (Access denied).

My guess is that the Service Control Manager is creating the Service process with security on it such that my user application cannot "open" it. Can any 'NT Service guru' out there confirm this?

kfe
ASKER CERTIFIED SOLUTION
Avatar of vinniew
vinniew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Suggestion: Communicate using named pipes.