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!