Another Example Using Shared Memory
The following is another program example that supposed to use the shared memory. The process uses the GetSharedMem() function implemented by the DLL to read a string from the shared memory. It is started by the parent process above.
Create a new empty Win32 console application project. Give a suitable project name and change the project location if needed.
Then, add the source file and give it a suitable name.
Next, add the following source code.
// Child process
extern C void GetSharedMem(LPWSTR lpszBuf, DWORD cchSize);
wprintf(LChild process read from shared memory: %s\n, cBuf);
Next add the path to the DLL/library and the library file name.
Build the project. Then we need to copy the DLL into the project’s Debug folder so that it can be found during the run-time else the following error screen will be displayed.
For the sake of demonstration, copy the DLL into the application Debug’s project folder and re-run the project.
The following is the sample output.