If you are not using any synchronization to ensure that the process that calls OpenFileMapping does not make the call before the process that calls CreateFileMapping has created the shared memory then the described error can occur. Instead of using OpenFileMapping you can use CreateFileMapping in both processes.
According to Microsoft's documentation at Creating a File Mapping Object "The first process that calls CreateFileMapping creates the file mapping object. Processes calling CreateFileMapping for an existing object receive a handle to the existing object. You can tell whether or not a successful call to CreateFileMapping created or opened the file mapping object by calling the GetLastError function. GetLastError returns NO_ERROR to the creating process and ERROR_ALREADY_EXISTS to subsequent processes."