Qt World Summit: Register Today!

QSharedMemory between local process and Windows Service

  • We have been successfully using shared memory to communicate between several Windows processes. However, we've recently run into an issue with sharing memory between a Windows service and a local user process.

    Whenever the local process or the service attempts to attach to shared memory created by the other process we get the error "QSharedMemory::handle: doesn't exist".

    When running the service as a command line application everything works fine.

    I'm assuming this has something to do with how Windows handles services, but can't find any good information on the subject. Does anyone have any potential insight or is this an invalid workflow?


  • It's a security feature. windoze services run in a different context to prevent exactly what you are trying to do.

  • @AccWhid
    As @Kent-Dorfman says, Windoze is precisely preventing you from trying to do something as naughty as this! :) You certainly don't want to be sharing memory between elevated and user processes. It's "an invalid workflow" in that you shouldn't be sharing memory like this!

    I think you're going to really have to rethink your mode of operation. What do you use it for? You would normally be expected to share data via socket/file, which is a quite different architecture. Otherwise, I don't know, you might find that you can use "named" shared memory/memory mapped files to achieve this, e.g. read https://docs.microsoft.com/en-us/windows/win32/memory/creating-named-shared-memory.

Log in to reply