title: How can we read memory mapped file data of 32 bit 3rd party application from a windows service application?
body: <p>I have a 32 bit third party application's dll. It is of type library project and creates a memory Mapped File named <strong>MappedObject</strong>. This is the section of code indicating generation of mmf file:-</p>
  
  <pre><code>#include "stdafx.h"
  #include "dllmain.h"
  #include &lt;stdio.h&gt;
  #include &lt;tchar.h&gt;
  
  #include &lt;ctime&gt;
  
  
  #pragma comment(lib, "user32.lib")
  
  #define BUF_SIZE 48
  
  HANDLE hMapFile;
  LPCTSTR memoryBuf;
  TCHAR szName[] = TEXT("MappedObject");
  /**
   */
  BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
  {
      switch (ul_reason_for_call)
      {
      case DLL_PROCESS_ATTACH:
          {
          hMapFile = CreateFileMapping(hMapFile, NULL, PAGE_READWRITE, 0, BUF_SIZE, szName);
  
          if (hMapFile == NULL)
          {
              _tprintf(TEXT("Could not create file mapping object (%d).\n"),
                  GetLastError());
              return FALSE;
          }
          memoryBuf = (LPTSTR)MapViewOfFile(hMapFile,   // handle to map object
              FILE_MAP_WRITE, // read/write permission
              0,
              0,
              BUF_SIZE);
  
          if (memoryBuf == NULL)
          {
              _tprintf(TEXT("Could not map view of file (%d).\n"),
                  GetLastError());
  
              CloseHandle(hMapFile);
  
              return FALSE;
          }
          }
          break;
  </code></pre>
  
  <p>Now there is a 2nd C# application which must read this memory mapped file. The C# application is of type Windows Service. This is a section of code :-</p>
  
  <pre><code> try
              {
                  MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(@"Global\MappedObject", MemoryMappedFileRights.ReadWrite, HandleInheritability.None);
                  Library.WriteErrorLog("Mapped File Accessed");
                  MemoryMappedViewAccessor mmfViewStream = mmf.CreateViewAccessor(0, MMF_MAX_SIZE, MemoryMappedFileAccess.Read);
                  byte[] buffer = new byte[MMF_MAX_SIZE];
                  String message = String.Empty;
                  while (mmfViewStream.CanRead)
                  {
                      mmfViewStream.ReadArray(0, buffer, 0, MMF_MAX_SIZE);
  }
  </code></pre>
  
  <p>Whenever the 2nd application i.e. c# application tries to access memory mapped file. It cannot find it. 
  What really is weird is that If I build a simple console application and try to access the memory mapped file, I can. However, there seems to be a problem in windows service type application. Can anyone please point to me in right direction??</p>
  
  <p><strong>For your information, the mapped file name is MappedObject and I have tried to access it through MappedObject, @"Global\Mapped" in my service application. However, it doesn't seem to work. I am on Windows 10 64bit. The 3rd party application is of 32 bit. The service application is also of 32 bit(I am using x86 release feature of visual studio of build).</strong> </p>