<?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[shared memory Probleme (MappedFile)]]></title><description><![CDATA[<p>also folgende Funktion (1:1 aus meinem projekt kopiert) funktioniert bei mir einfach nicht... Der Sinn ist eigetnlich, daß ich die mit NULL vorinitialisierte variable &quot;all_mipts_ships&quot; einfach nicht schaffe mit dem Wert aus dem shard memory upzudaten... Aber es gibt auch keinen Absturz des Programmes, was heisst, &quot;all_mipts_ships&quot; belibt immer auf NULL.</p>
<p>(der Sinn ist ein Datenaustausch über eine beliebige Anzahl dll's hinweg, die aber alle vom gleichen programm direkt hintereinander aufgerufen werden (kein multithread Programm). Ich will im shared memory einen pointer speichern, der auf eine Liste mit Objekten zeigt. Diese liste ist vom Typ &quot;SHIPLIST&quot;) Vielleicht fällt ja jemandem ein Fehler auf.. der Code ist eine klein-bischen abgewandelte Form aus dem beispiel aus der MSDN doku.</p>
<pre><code class="language-cpp">int MIPTS_Module::UpdateSharedMemory(){
	//the following code is taken from http://msdn2.microsoft.com/en-us/library/aa366551(VS.85).aspx

	struct SHIPLISTINFO{
		bool exists;
		SHIPLIST* pshiplist;
	};

	const int BUF_SIZE=256;
	const TCHAR szName[]=TEXT(&quot;MIPTS\\shiplistpointer&quot;);

	HANDLE hMapFile;
	LPVOID pBuf;

	hMapFile = CreateFileMapping(
	                 INVALID_HANDLE_VALUE,    // use paging file
	                 NULL,                    // default security 
	                 PAGE_READWRITE,          // read/write access
	                 0,                       // max. object size 
	                 BUF_SIZE,                // buffer size  
	                 szName);                 // name of mapping object

	int hMapError=GetLastError();	    

	if (hMapFile == NULL){ 
		cerr&lt;&lt;&quot;Could not create file mapping object &quot;&lt;&lt;hMapError&lt;&lt;&quot;\n&quot;;
		return 1;
	}
	pBuf = MapViewOfFile(hMapFile,   // handle to map object
	                FILE_MAP_ALL_ACCESS, // read/write permission
	                0,                   
	                0,                   
	                BUF_SIZE); 

	if (pBuf == NULL) 
	{ 
		cerr&lt;&lt;&quot;Could not map view of file &quot;&lt;&lt;GetLastError()&lt;&lt;endl; 
		return 2;
	}else if(hMapError!=ERROR_ALREADY_EXISTS)
	{
		SHIPLIST *slinfo=new SHIPLIST();

		CopyMemory((PVOID)pBuf, (PVOID)(&amp;slinfo), sizeof(slinfo));
	}

	SHIPLIST *slinfo;

	CopyMemory((PVOID)(&amp;slinfo), (PVOID)pBuf, sizeof(slinfo));

	all_mipts_ships=slinfo;

	UnmapViewOfFile(pBuf);

	CloseHandle(hMapFile);			

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/203819/shared-memory-probleme-mappedfile</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 03:42:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/203819.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 26 Jan 2008 20:37:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to shared memory Probleme (MappedFile) on Sat, 26 Jan 2008 20:37:24 GMT]]></title><description><![CDATA[<p>also folgende Funktion (1:1 aus meinem projekt kopiert) funktioniert bei mir einfach nicht... Der Sinn ist eigetnlich, daß ich die mit NULL vorinitialisierte variable &quot;all_mipts_ships&quot; einfach nicht schaffe mit dem Wert aus dem shard memory upzudaten... Aber es gibt auch keinen Absturz des Programmes, was heisst, &quot;all_mipts_ships&quot; belibt immer auf NULL.</p>
<p>(der Sinn ist ein Datenaustausch über eine beliebige Anzahl dll's hinweg, die aber alle vom gleichen programm direkt hintereinander aufgerufen werden (kein multithread Programm). Ich will im shared memory einen pointer speichern, der auf eine Liste mit Objekten zeigt. Diese liste ist vom Typ &quot;SHIPLIST&quot;) Vielleicht fällt ja jemandem ein Fehler auf.. der Code ist eine klein-bischen abgewandelte Form aus dem beispiel aus der MSDN doku.</p>
<pre><code class="language-cpp">int MIPTS_Module::UpdateSharedMemory(){
	//the following code is taken from http://msdn2.microsoft.com/en-us/library/aa366551(VS.85).aspx

	struct SHIPLISTINFO{
		bool exists;
		SHIPLIST* pshiplist;
	};

	const int BUF_SIZE=256;
	const TCHAR szName[]=TEXT(&quot;MIPTS\\shiplistpointer&quot;);

	HANDLE hMapFile;
	LPVOID pBuf;

	hMapFile = CreateFileMapping(
	                 INVALID_HANDLE_VALUE,    // use paging file
	                 NULL,                    // default security 
	                 PAGE_READWRITE,          // read/write access
	                 0,                       // max. object size 
	                 BUF_SIZE,                // buffer size  
	                 szName);                 // name of mapping object

	int hMapError=GetLastError();	    

	if (hMapFile == NULL){ 
		cerr&lt;&lt;&quot;Could not create file mapping object &quot;&lt;&lt;hMapError&lt;&lt;&quot;\n&quot;;
		return 1;
	}
	pBuf = MapViewOfFile(hMapFile,   // handle to map object
	                FILE_MAP_ALL_ACCESS, // read/write permission
	                0,                   
	                0,                   
	                BUF_SIZE); 

	if (pBuf == NULL) 
	{ 
		cerr&lt;&lt;&quot;Could not map view of file &quot;&lt;&lt;GetLastError()&lt;&lt;endl; 
		return 2;
	}else if(hMapError!=ERROR_ALREADY_EXISTS)
	{
		SHIPLIST *slinfo=new SHIPLIST();

		CopyMemory((PVOID)pBuf, (PVOID)(&amp;slinfo), sizeof(slinfo));
	}

	SHIPLIST *slinfo;

	CopyMemory((PVOID)(&amp;slinfo), (PVOID)pBuf, sizeof(slinfo));

	all_mipts_ships=slinfo;

	UnmapViewOfFile(pBuf);

	CloseHandle(hMapFile);			

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1444208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1444208</guid><dc:creator><![CDATA[yeus]]></dc:creator><pubDate>Sat, 26 Jan 2008 20:37:24 GMT</pubDate></item><item><title><![CDATA[Reply to shared memory Probleme (MappedFile) on Sat, 26 Jan 2008 21:01:38 GMT]]></title><description><![CDATA[<p>yeus schrieb:</p>
<blockquote>
<pre><code class="language-cpp">SHIPLIST *slinfo;
	
	CopyMemory((PVOID)(&amp;slinfo), (PVOID)pBuf, sizeof(slinfo));
		
	all_mipts_ships=slinfo;
</code></pre>
</blockquote>
<p>Das sollte dir um die Ohren fliegen. Wenn ich intelligent raten müsste, würde ich vermuten, dass es ungefähr so aussehen sollte:</p>
<pre><code class="language-cpp">...
    if (pBuf == NULL)
    {
        cerr&lt;&lt;&quot;Could not map view of file &quot;&lt;&lt;GetLastError()&lt;&lt;endl;
        return 2;
    }
    if(hMapError!=ERROR_ALREADY_EXISTS)
    {
        all_mipts_ships = all_mipts_ships != NULL ? new(all_mipts_ships) SHIPLIST() : new SHIPLIST();
        memcpy( pBuf, all_mipts_ships, sizeof *all_mipts_ships );
    }
    else
        memcpy( all_mipts_ships, pBuf, sizeof *all_mipts_ships );

    UnmapViewOfFile(pBuf);
...
</code></pre>
<p>ohne ein paar Deklarationen und Erklärungen, was passieren soll, ist das natürlich nur ein Blick durch die Glaskugel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1444212</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1444212</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 26 Jan 2008 21:01:38 GMT</pubDate></item><item><title><![CDATA[Reply to shared memory Probleme (MappedFile) on Sun, 27 Jan 2008 13:15:45 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-403.html" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-4.html" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1444485</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1444485</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sun, 27 Jan 2008 13:15:45 GMT</pubDate></item></channel></rss>