Hello,
here is another method with memory-mapped files:
creating-named-shared-memory
Regards, Guido
How to share data between Service Program and Desktop Program?
I want to share data between service program and desktop program.
I made very simple DLL file like below
#pragma data_seg(".MyShare")
char g_player_running = 0; // 0 - No Running, 1 - Running, 2 - User Terminated
#pragma data_seg()
#pragma comment( linker, "/SECTION:.MyShare,RWS")
extern "C" _declspec(dllexport) char GetPlayerRunningStatus()
{
return g_player_running;
}
extern "C" _declspec(dllexport) void SetPlayerRunningStatus(char AStatus)
{
g_player_running = AStatus;
}
extern "C" _declspec(dllexport) char* GetPlayerRunningStatusPointer()
{
return &g_player_running;
}
Both service program and desktop program started with loading the dll file.
But, the data was not shared.
If desktop program runs twice, data sharing works well...
I used the function (GetPlayerRunningStatusPointer) to get address of the data variable.
Both service program and desktop program get the same address.
But Data sharing is not working......
Is it impossible? or Should I use another method?
2 answers
Sort by: Most helpful
-
Guido Franzke 2,186 Reputation points
2021-01-29T07:11:29.123+00:00 -
Drake Wu - MSFT 991 Reputation points
2021-01-29T07:25:09.153+00:00 Hi, @재환 주 Services are running in the session 0, and Shared sections don't work across session boundaries any more.
You could choose the most suitable IPC method in this document: Interprocess Communications. I suggest to use File Mapping to achieve shared memory.
Here is the related issue on stackoverflow: https://stackoverflow.com/a/898863/10611792
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.