<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[file mapping]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{  
	HANDLE h_File;
         HANDLE h_FileMapping;
         LPVOID lpv_FileMappingPointer;

	// File erzeugen
	h_File = CreateFile(&quot;C:\\Werte.txt&quot;, 
				GENERIC_READ | GENERIC_WRITE, 
				0,
				NULL,
				OPEN_EXISTING,
				FILE_ATTRIBUTE_NORMAL,
				NULL);

	if (h_File == INVALID_HANDLE_VALUE) 
	{
	      MessageBox(NULL, &quot;Can not open file&quot;, &quot;Error&quot;, 0);
               return 0;
	}

         // FileMapping erzeugen
	h_FileMapping = CreateFileMapping(h_File,
				NULL,
				PAGE_READWRITE,
				0,
				0,
				&quot;FileMapping&quot;);

	if (h_FileMapping == INVALID_HANDLE_VALUE) 
         { 
            if (h_File != INVALID_HANDLE_VALUE) 
		{
			MessageBox(NULL, &quot;Can not open file mapping&quot;, &quot;Error&quot;, 0);
            CloseHandle(h_File); 
		}
        return 0; 
    }

	lpv_FileMappingPointer = MapViewOfFile(h_FileMapping,
				FILE_MAP_ALL_ACCESS,
				0,
				0,
				0);

   //static_cast&lt;int&gt;(* static_cast&lt;int*&gt;(lpv_FileMappingPointer)) = 1;
   *(int*)lpv_FileMappingPointer=1;

   UnmapViewOfFile(lpv_FileMappingPointer);
   CloseHandle(h_FileMapping);
   CloseHandle(h_File);

   return 0;
}
</code></pre>
<p>hi leute!</p>
<p>warum funktioniert das nicht?</p>
<pre><code class="language-cpp">Unhandled exception at 0x0041c4d8 in Client.exe: 0xC0000005: Access violation writing location 0x00000000.
</code></pre>
<p>hab mal debuggt...h_FileMapping hat einen ungültigen handle...hm ka warum!??</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/91453/file-mapping</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 06:45:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/91453.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Nov 2004 19:23:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to file mapping on Mon, 08 Nov 2004 19:23:53 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{  
	HANDLE h_File;
         HANDLE h_FileMapping;
         LPVOID lpv_FileMappingPointer;

	// File erzeugen
	h_File = CreateFile(&quot;C:\\Werte.txt&quot;, 
				GENERIC_READ | GENERIC_WRITE, 
				0,
				NULL,
				OPEN_EXISTING,
				FILE_ATTRIBUTE_NORMAL,
				NULL);

	if (h_File == INVALID_HANDLE_VALUE) 
	{
	      MessageBox(NULL, &quot;Can not open file&quot;, &quot;Error&quot;, 0);
               return 0;
	}

         // FileMapping erzeugen
	h_FileMapping = CreateFileMapping(h_File,
				NULL,
				PAGE_READWRITE,
				0,
				0,
				&quot;FileMapping&quot;);

	if (h_FileMapping == INVALID_HANDLE_VALUE) 
         { 
            if (h_File != INVALID_HANDLE_VALUE) 
		{
			MessageBox(NULL, &quot;Can not open file mapping&quot;, &quot;Error&quot;, 0);
            CloseHandle(h_File); 
		}
        return 0; 
    }

	lpv_FileMappingPointer = MapViewOfFile(h_FileMapping,
				FILE_MAP_ALL_ACCESS,
				0,
				0,
				0);

   //static_cast&lt;int&gt;(* static_cast&lt;int*&gt;(lpv_FileMappingPointer)) = 1;
   *(int*)lpv_FileMappingPointer=1;

   UnmapViewOfFile(lpv_FileMappingPointer);
   CloseHandle(h_FileMapping);
   CloseHandle(h_File);

   return 0;
}
</code></pre>
<p>hi leute!</p>
<p>warum funktioniert das nicht?</p>
<pre><code class="language-cpp">Unhandled exception at 0x0041c4d8 in Client.exe: 0xC0000005: Access violation writing location 0x00000000.
</code></pre>
<p>hab mal debuggt...h_FileMapping hat einen ungültigen handle...hm ka warum!??</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/647655</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/647655</guid><dc:creator><![CDATA[nike_]]></dc:creator><pubDate>Mon, 08 Nov 2004 19:23:53 GMT</pubDate></item><item><title><![CDATA[Reply to file mapping on Mon, 08 Nov 2004 19:42:52 GMT]]></title><description><![CDATA[<p>Ist lpv_FileMappingPointer vielleicht ein NULL-Pointer?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/647679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/647679</guid><dc:creator><![CDATA[blub_]]></dc:creator><pubDate>Mon, 08 Nov 2004 19:42:52 GMT</pubDate></item><item><title><![CDATA[Reply to file mapping on Mon, 08 Nov 2004 19:56:05 GMT]]></title><description><![CDATA[<p>LPVOID lpv_FileMappingPointer;<br />
ist ja ein long pointer vom typ void!</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/647699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/647699</guid><dc:creator><![CDATA[nike_]]></dc:creator><pubDate>Mon, 08 Nov 2004 19:56:05 GMT</pubDate></item><item><title><![CDATA[Reply to file mapping on Mon, 08 Nov 2004 20:16:06 GMT]]></title><description><![CDATA[<p>Was soll uns das jetzt sagen? MapViewOfFile kann einen NULL-Pointer zurückgeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/647719</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/647719</guid><dc:creator><![CDATA[blub_]]></dc:creator><pubDate>Mon, 08 Nov 2004 20:16:06 GMT</pubDate></item><item><title><![CDATA[Reply to file mapping on Mon, 08 Nov 2004 20:19:10 GMT]]></title><description><![CDATA[<p>blub_ schrieb:</p>
<blockquote>
<p>Was soll uns das jetzt sagen? MapViewOfFile kann einen NULL-Pointer zurückgeben.</p>
</blockquote>
<p>ich lese grad:<br />
CreateFileMapping returns another handle that you have to save, or NULL if failed.</p>
<p>warum ich einen NULL pointer bekomme hab ich keinen schimmer;-(</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/647722</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/647722</guid><dc:creator><![CDATA[nike_]]></dc:creator><pubDate>Mon, 08 Nov 2004 20:19:10 GMT</pubDate></item><item><title><![CDATA[Reply to file mapping on Mon, 08 Nov 2004 20:22:46 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">if(h_FileMapping == NULL)
	{
        LPVOID lpMsgBuf; 
        FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | 
                                        FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 
                                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpMsgBuf, 0, NULL); 
        MessageBox (NULL, (LPCTSTR)lpMsgBuf, &quot;Error: CreateFile&quot;, MB_OK | MB_ICONINFORMATION); 
        LocalFree (lpMsgBuf);
	}
</code></pre>
<p>Gibt mir folgende Fehlermeldung aus:<br />
Das Handle ist ungültig;-((</p>
<p>hm</p>
]]></description><link>https://www.c-plusplus.net/forum/post/647726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/647726</guid><dc:creator><![CDATA[nike_]]></dc:creator><pubDate>Mon, 08 Nov 2004 20:22:46 GMT</pubDate></item><item><title><![CDATA[Reply to file mapping on Mon, 08 Nov 2004 20:44:34 GMT]]></title><description><![CDATA[<p>Hier ein Ausschnitt aus der Dokumentation zu CreateFileMapping():</p>
<blockquote>
<p><em>dwMaximumSizeLow</em><br />
Low-order DWORD of the maximum size of the file mapping object. If this parameter and dwMaximumSizeHigh are zero, the maximum size of the file mapping object is equal to the current size of the file identified by hFile.<br />
<strong>An attempt to map a file with a length of zero in this manner fails with an error code of ERROR_FILE_INVALID</strong>. Applications should test for files with a length of zero and reject such files.</p>
</blockquote>
<p>Könnte das vielleicht das Problem sein?<br />
Wenn deine Datei wirklich eine Größe von 0 Bytes sein, dann muß du die gewünschte Größe des Mappings angeben anstatt (mit dem Wert 0) automatisch das ganze File zu mappen.</p>
<p>- Raving Tux</p>
]]></description><link>https://www.c-plusplus.net/forum/post/647746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/647746</guid><dc:creator><![CDATA[Raving Tux]]></dc:creator><pubDate>Mon, 08 Nov 2004 20:44:34 GMT</pubDate></item><item><title><![CDATA[Reply to file mapping on Mon, 08 Nov 2004 20:58:35 GMT]]></title><description><![CDATA[<p>ja könnte sein...denn ich erstelle die datei erst, also die datei existiert noch nicht...<br />
#OPEN_ALWAYS: create a new file if it doesn't exist, or open the old if it exists.</p>
<p>gewünschte Größe des Mappings? hab da 1 genommen...und es geht;-) wie interpretiert man nun die 1????</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/647757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/647757</guid><dc:creator><![CDATA[nike_]]></dc:creator><pubDate>Mon, 08 Nov 2004 20:58:35 GMT</pubDate></item><item><title><![CDATA[Reply to file mapping on Mon, 08 Nov 2004 21:35:31 GMT]]></title><description><![CDATA[<p>nike_ schrieb:</p>
<blockquote>
<p>gewünschte Größe des Mappings? hab da 1 genommen...und es geht;-) wie interpretiert man nun die 1????</p>
</blockquote>
<p>Nan ja, wie in der Doku zu CreateFileMapping() nachzulesen ist, ist das die maximale Größe des Mappings, d.h. du kannst mit MapViewOfFile keine größere View mappen.</p>
<p>Du solltest dir die Doku zu CreateFileMapping und MapViewOfFile (noch) mal genau durchlesen. Da sollte eigentlich alles drinstehen.</p>
<p>- Raving Tux</p>
]]></description><link>https://www.c-plusplus.net/forum/post/647788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/647788</guid><dc:creator><![CDATA[Raving Tux]]></dc:creator><pubDate>Mon, 08 Nov 2004 21:35:31 GMT</pubDate></item><item><title><![CDATA[Reply to file mapping on Tue, 09 Nov 2004 23:30:17 GMT]]></title><description><![CDATA[<p>hi!<br />
Ich will das File Mapping der Datei in 3 Teile aufteilen...<br />
File file(fileName);<br />
FileMapping map(file, SEGMENTSIZE);<br />
lpv_FileMappPtr=MapViewOfFile(map1.getHandle(),FILE_MAP_ALL_ACCESS,0,0,0);</p>
<p>brauch ich dann 3 mal FileMapping? dann wird die datei 3 mal grösser...ok<br />
und 3 mal das File Mapping mit MapViewOfFile auflisten?</p>
<p>ist das ok?</p>
<p>in das File mappen:<br />
-------------------</p>
<p>void* lpv_FileMappPtr1;</p>
<p>File file(fileName); // Instanz der Klasse File erstellen...mit CreateFile datei erstellen...<br />
FileMapping map(file, SEGMENTSIZE);</p>
<p>lpv_FileMappPtr=MapViewOfFile(map1.getHandle(),FILE_MAP_ALL_ACCESS,0,0,0);</p>
<p>* static_cast&lt;int*&gt;(lpv_FileMappPtr) = 12; // Wert 12 reinschreiben...</p>
<p>schreibt man sonst auch so in die datei? //SetFilePointer...nimmt man auch noch..ok</p>
<p>cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/648477</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/648477</guid><dc:creator><![CDATA[nike_]]></dc:creator><pubDate>Tue, 09 Nov 2004 23:30:17 GMT</pubDate></item></channel></rss>