<?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[Fehler bei Pfad der exe]]></title><description><![CDATA[<p>Hi @ ALl.</p>
<p>Ich möchte der Klasse im Konstrukter den Pfad/Dateinamen der Exe-Datei vermitteln.<br />
das sind LPCSTR-variablen.<br />
Im header:</p>
<pre><code class="language-cpp">public: LPCSTR lpPath,lpFile;
</code></pre>
<p>Im Konstruktor:</p>
<pre><code class="language-cpp">{
	// Get module path
	char szBuffer[MAX_PATH+2];
	char szPath[MAX_PATH+2];
	char *pFilename;

	GetModuleFileName (NULL, szBuffer, MAX_PATH);
	GetFullPathName (szBuffer, sizeof (szBuffer), szPath, &amp;pFilename);
	szPath[pFilename-szPath] = '\0';

	lpPath = szPath;
	lpFile = pFileName;

	MessageBox(NULL,lpPath,&quot;Path&quot;,MB_OK);
	MessageBox(NULL,lpFile,&quot;File&quot;,MB_OK);
}
</code></pre>
<p>thx!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/188471/fehler-bei-pfad-der-exe</link><generator>RSS for Node</generator><lastBuildDate>Fri, 03 Jul 2026 16:34:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/188471.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 31 Jul 2007 16:12:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler bei Pfad der exe on Tue, 31 Jul 2007 16:12:57 GMT]]></title><description><![CDATA[<p>Hi @ ALl.</p>
<p>Ich möchte der Klasse im Konstrukter den Pfad/Dateinamen der Exe-Datei vermitteln.<br />
das sind LPCSTR-variablen.<br />
Im header:</p>
<pre><code class="language-cpp">public: LPCSTR lpPath,lpFile;
</code></pre>
<p>Im Konstruktor:</p>
<pre><code class="language-cpp">{
	// Get module path
	char szBuffer[MAX_PATH+2];
	char szPath[MAX_PATH+2];
	char *pFilename;

	GetModuleFileName (NULL, szBuffer, MAX_PATH);
	GetFullPathName (szBuffer, sizeof (szBuffer), szPath, &amp;pFilename);
	szPath[pFilename-szPath] = '\0';

	lpPath = szPath;
	lpFile = pFileName;

	MessageBox(NULL,lpPath,&quot;Path&quot;,MB_OK);
	MessageBox(NULL,lpFile,&quot;File&quot;,MB_OK);
}
</code></pre>
<p>thx!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1335962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1335962</guid><dc:creator><![CDATA[Script-Styler]]></dc:creator><pubDate>Tue, 31 Jul 2007 16:12:57 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Pfad der exe on Tue, 31 Jul 2007 20:02:25 GMT]]></title><description><![CDATA[<p>Eine etwas genauere Fehlerbeschreibung wäre evtl. hilfreich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1336107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1336107</guid><dc:creator><![CDATA[Analog Bit]]></dc:creator><pubDate>Tue, 31 Jul 2007 20:02:25 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Pfad der exe on Tue, 31 Jul 2007 21:24:20 GMT]]></title><description><![CDATA[<p>jo, die lpFile-variable bekommt kein dateinamen ab.<br />
warum?<br />
ich hab ihr doch den pFilename gegeben.<br />
kann man das auch etwas eleganter machen, also ohne die char-zwischenvariablen?<br />
danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1336153</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1336153</guid><dc:creator><![CDATA[Script-Styler]]></dc:creator><pubDate>Tue, 31 Jul 2007 21:24:20 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Pfad der exe on Tue, 31 Jul 2007 21:35:31 GMT]]></title><description><![CDATA[<p>Fix gebastelt und ungetestet:</p>
<pre><code class="language-cpp">TCHAR myBuffer[MAX_PATH];
TCHAR myPath[MAX_PATH];
TCHAR myFile[MAX_PATH];
GetModuleFileName(NULL, myBuffer, MAX_PATH);

lstrcpy(myPath,myBuffer);   // Vollen Pfad nach myPath kopieren
PathRemoveFileSpec(myPath); // Den Dateinamen aus myPath raus killen

lstrcpy(myFile,myBuffer);   // Vollen Pfad nach myFile kopieren
PathStripPath(myFile);      // Reinen Pfad aus myFile raus killen

MessageBox(NULL,myFile,TEXT(&quot;Dateiname&quot;),MB_OK);
MessageBox(NULL,myPath,TEXT(&quot;Pfad&quot;),MB_OK);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1336162</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1336162</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Tue, 31 Jul 2007 21:35:31 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Pfad der exe on Tue, 31 Jul 2007 22:16:54 GMT]]></title><description><![CDATA[<p>Script-Styler schrieb:</p>
<blockquote>
<p>jo, die lpFile-variable bekommt kein dateinamen ab.<br />
warum?<br />
ich hab ihr doch den pFilename gegeben.</p>
</blockquote>
<p>Wenn du dir folgende Zeile (der Code kommt mir so bekannt vor <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> ) genauer betrachtest</p>
<pre><code class="language-cpp">szPath[pFilename-szPath] = '\0';
</code></pre>
<p>welche hier gleichbedeutend ist mit</p>
<pre><code class="language-cpp">*pFilename = '\0';
</code></pre>
<p>solltest du den 'Fehler' schon sehen.</p>
<p>Um das ganze also auf zwei char Arrays zu begrenzen, Dateinamen nach szBuffer kopieren und dann erst den Inhalt der Anfangsadresse mit dem Dateinamen auf Null setzen</p>
<pre><code class="language-cpp">lstrcpy(szBuffer, pFilename);
*pFilename = '\0';
</code></pre>
<p>Achtung der Pfad hat im Gegensatz zu geeky's Methode immer einen Backslash am Ende. Allerdings musst du hier gegen keine zusätzliche lib linken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1336182</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1336182</guid><dc:creator><![CDATA[Analog Bit]]></dc:creator><pubDate>Tue, 31 Jul 2007 22:16:54 GMT</pubDate></item></channel></rss>