Is is possible to create a semaphore accessable to both Windows and Qt applications?
I tried to create a named semaphore in a Windows application using following code:
m_hSemaphore = ::CreateSemaphore(NULL, 0, 100, "semaphore_test");
and in my Qt application I open a semaphore of the same name:
pSemaphore = new QSystemSemaphore(tr("semaphore_test"), 0, QSystemSemaphore::Open);
But when the semaphore is released in Windows application, in Qt application,
is still blocked, which means two applications are not accessing the samesemaphore.
Is there a way to make both applications access the same semaphore? The similar problem also exists in accessing shared memory in both Windows and Qt applications.
AFAIK Qt will decorate the Semaphore name, when using QSystemSemaphore().
You can use a tool such as ProcessExplorer to lookup the actual (native) name of the Semaphore...
!http://imageshack.us/a/img690/9056/clipboard01yi.png(Screenshot from ProcessExplorer)!
Looks like the string "qipc_systemsem_" followed by a hash of the specified string is used ;-)
bq. Thank you very much for your help! Now I can make Windows application and Qt application use a same semaphore.
ProcessExplorer does not show shared memory used by a process, so making Windows application and Qt application use same shared memory is still a problem. Any ideas?
The "shared" memory is nothing but a "memory mapped file", one that is backed by the system page file rather than by a file system file. Doesn't it show up under the file handles in ProcessExplorer?
No, it does not show up.
I'm now at home and just check it. It does show up! But as a "section", not as a "file" ;-)
I see, thanks! By the way, I just noticed that QSharedMemory::setNativeKey will set the native, platform specific key for this shared memory object, that will also help in Qt code to connect to shared memory created from Windows code.