Sharing memory between 32-bit and 64-bit processes in Windows
<p>I am facing a problem of sharing memory between two processes running under Windows 64-bit</p>

<p>The goal is to share a memory mapping created using a 32-bit process, which the 64-bit process writes to.</p>

<p>I am using the following to create the memory under the 32-bit application:</p>

<pre><code>m_hSharedFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, NULL, BUF_SIZE, memName);
m_pSharedBuf = MapViewOfFile(m_hSharedFile, FILE_MAP_WRITE, 0, 0, 0);
</code></pre>

<p>And the following in the 64-bit application for opening the shared memory:</p>

<pre><code>m_hSharedFile = OpenFileMapping(FILE_MAP_WRITE, FALSE, m_memName.c_str());
m_pSharedBuf = MapViewOfFile(m_hSharedFile, FILE_MAP_WRITE, 0, 0, 0);
</code></pre>

<p>(Edited) The problem is the data written in the 64-bit process doesn't match the data read by the host 32-bit process.</p>

<p>When I try to run the same programs as 32-bit &lt;--> 32-bit, the memory mapping works fine, and the data is received with no problems.</p>

<p>I guess the problem resides in the memory addressing. Are there any workarounds to resolve this problem?</p>

<p><strong>Update:</strong>
The problem is resolved. The data structure that represents the shared memory was the follwoing:</p>

<pre><code>struct SH_MEM {
     size_t size;
     size_t max_size;
/***/
}
</code></pre>

<p>I missed the fact that <code>size_t</code> is architecture-dependent (4 bytes for 32-bit apps and 8 bytes for 64-bit apps).</p>

<p>I forced the data types to be 4 bytes, using <code>int32_t</code> instead (with header file <code>cstdint</code>).</p>