<?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[Defekte Pipe]]></title><description><![CDATA[<p>Hi,</p>
<p><strong>Ziel</strong><br />
Ich möchte einen Subthread erstellen, welcher dann den Benutzer in der Console abfragen (Endlosschleife) und die Meldungen/Texte an den Mainthread soll. Der Mainthread soll alles via printf auf den Bildschirm drucken.</p>
<p><strong>Was es jetzt macht</strong><br />
Das Programm fragt mich einmal was ich für einen Text eingeben möchte, und dann bleibt es in einer Endlosschleife.</p>
<p><strong>Bitte beachten</strong><br />
Es geht primär um die Pipe, dass die Kommunikation funktioniert, jegliche Kritik zu anderen Dingen die nicht relevant sind bitte ich zu unterlassen. Danke.</p>
<p><strong>Der Code</strong></p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;windows.h&gt;

//pipe
HANDLE hPipe;
DWORD BytesRead, BytesWritten;
char Buffer[256];

DWORD WINAPI FirstThread(PVOID pvParam)
{
      char msg[201];

      while(1)
      {
            printf(&quot;\nWhat do you want to say? Type in (MaxChars: 201):&quot;);
            fgets(msg, 201, stdin);
            if(ConnectNamedPipe(hPipe, NULL) == 0)
            {
                  printf(&quot;ConnectNamedPipe (Thread) failed with error %d\n&quot;, GetLastError());
                  break;      
            }
            if(WriteFile(hPipe, msg, 201, &amp;BytesWritten, NULL) == 0)
            {
                  printf(&quot;WriteFile failed with error %d\n&quot;, GetLastError());
                  break;      
            }
      }

      return 0;      
}

int main(int argc, char *argv[])
{
  int x = 0;
  DWORD dwThreadId;
  HANDLE hThread; 

  if( (hPipe = CreateNamedPipe(&quot;\\\\.\\Pipe\\t3stp1p3&quot;, 
            PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, 
            0, 0, 1000, NULL) ) == INVALID_HANDLE_VALUE)
     {
            printf(&quot;CreateNamedPipe failed with error %d\n&quot;, GetLastError());
            return 1;       
     }

  //puts(&quot;Before the Thread&quot;);
  hThread = CreateThread(NULL, 0, FirstThread, (PVOID)&amp;x, 0, &amp;dwThreadId);
  //printf(&quot;The Thread ID is %d!\n&quot;, dwThreadId);
  //puts(&quot;After the Thread&quot;);

  while(1)
  {
      if(ConnectNamedPipe(hPipe, NULL) == 0)
      {
            printf(&quot;ConnectNamedPipe failed with error %d\n&quot;, GetLastError());
            break;      
      }     

      while(ReadFile(hPipe, Buffer, sizeof(Buffer), &amp;BytesRead, NULL) &gt; 0)
      {
            printf(&quot;\n-&gt; I got %d bytes: '%s'\n&quot;, BytesRead, Buffer);      
      }     
  }
  CloseHandle(hPipe);
  CloseHandle(hThread);

  return 0;
}
</code></pre>
<p>Ich wünsche euch einen guten Rutsch ins neue Jahr!</p>
<p>Vielen Dank und Gruss, Lot-Ionan</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/168995/defekte-pipe</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 03:04:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/168995.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 30 Dec 2006 21:18:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Defekte Pipe on Sat, 30 Dec 2006 21:18:35 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p><strong>Ziel</strong><br />
Ich möchte einen Subthread erstellen, welcher dann den Benutzer in der Console abfragen (Endlosschleife) und die Meldungen/Texte an den Mainthread soll. Der Mainthread soll alles via printf auf den Bildschirm drucken.</p>
<p><strong>Was es jetzt macht</strong><br />
Das Programm fragt mich einmal was ich für einen Text eingeben möchte, und dann bleibt es in einer Endlosschleife.</p>
<p><strong>Bitte beachten</strong><br />
Es geht primär um die Pipe, dass die Kommunikation funktioniert, jegliche Kritik zu anderen Dingen die nicht relevant sind bitte ich zu unterlassen. Danke.</p>
<p><strong>Der Code</strong></p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;windows.h&gt;

//pipe
HANDLE hPipe;
DWORD BytesRead, BytesWritten;
char Buffer[256];

DWORD WINAPI FirstThread(PVOID pvParam)
{
      char msg[201];

      while(1)
      {
            printf(&quot;\nWhat do you want to say? Type in (MaxChars: 201):&quot;);
            fgets(msg, 201, stdin);
            if(ConnectNamedPipe(hPipe, NULL) == 0)
            {
                  printf(&quot;ConnectNamedPipe (Thread) failed with error %d\n&quot;, GetLastError());
                  break;      
            }
            if(WriteFile(hPipe, msg, 201, &amp;BytesWritten, NULL) == 0)
            {
                  printf(&quot;WriteFile failed with error %d\n&quot;, GetLastError());
                  break;      
            }
      }

      return 0;      
}

int main(int argc, char *argv[])
{
  int x = 0;
  DWORD dwThreadId;
  HANDLE hThread; 

  if( (hPipe = CreateNamedPipe(&quot;\\\\.\\Pipe\\t3stp1p3&quot;, 
            PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, 
            0, 0, 1000, NULL) ) == INVALID_HANDLE_VALUE)
     {
            printf(&quot;CreateNamedPipe failed with error %d\n&quot;, GetLastError());
            return 1;       
     }

  //puts(&quot;Before the Thread&quot;);
  hThread = CreateThread(NULL, 0, FirstThread, (PVOID)&amp;x, 0, &amp;dwThreadId);
  //printf(&quot;The Thread ID is %d!\n&quot;, dwThreadId);
  //puts(&quot;After the Thread&quot;);

  while(1)
  {
      if(ConnectNamedPipe(hPipe, NULL) == 0)
      {
            printf(&quot;ConnectNamedPipe failed with error %d\n&quot;, GetLastError());
            break;      
      }     

      while(ReadFile(hPipe, Buffer, sizeof(Buffer), &amp;BytesRead, NULL) &gt; 0)
      {
            printf(&quot;\n-&gt; I got %d bytes: '%s'\n&quot;, BytesRead, Buffer);      
      }     
  }
  CloseHandle(hPipe);
  CloseHandle(hThread);

  return 0;
}
</code></pre>
<p>Ich wünsche euch einen guten Rutsch ins neue Jahr!</p>
<p>Vielen Dank und Gruss, Lot-Ionan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1200095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1200095</guid><dc:creator><![CDATA[Lot-Ionan]]></dc:creator><pubDate>Sat, 30 Dec 2006 21:18:35 GMT</pubDate></item><item><title><![CDATA[Reply to Defekte Pipe on Sat, 30 Dec 2006 21:21:15 GMT]]></title><description><![CDATA[<p>Benutz den Debucker.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1200097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1200097</guid><dc:creator><![CDATA[greggor]]></dc:creator><pubDate>Sat, 30 Dec 2006 21:21:15 GMT</pubDate></item><item><title><![CDATA[Reply to Defekte Pipe on Sat, 30 Dec 2006 21:58:33 GMT]]></title><description><![CDATA[<blockquote>
<p>und dann bleibt es in einer Endlosschleife.</p>
</blockquote>
<p>Ich würd eher sagen ConnectNamedPipe bleibt hängen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1200116</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1200116</guid><dc:creator><![CDATA[...........]]></dc:creator><pubDate>Sat, 30 Dec 2006 21:58:33 GMT</pubDate></item><item><title><![CDATA[Reply to Defekte Pipe on Sat, 30 Dec 2006 22:53:27 GMT]]></title><description><![CDATA[<p>Man muss sich glaub ich mit CreateFile mit der Pipe verbinden, erst dann kommt ConnectNamedPipe zurück.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1200130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1200130</guid><dc:creator><![CDATA[...........]]></dc:creator><pubDate>Sat, 30 Dec 2006 22:53:27 GMT</pubDate></item><item><title><![CDATA[Reply to Defekte Pipe on Sun, 31 Dec 2006 05:57:23 GMT]]></title><description><![CDATA[<p>Ich hab keinen Tip, dafür ne (möglicherweise) blöde Frage: wieso eine Pipe?</p>
<p>Ein EVENT + CRITICAL_SECTION + std::string z.B. sollte es genauso tun.<br />
Eine Pipe würde ich wirklich nur nehmen wenn du ACLs drauf setzen willst... sonst eher nen Socket (wenns über Prozessgrenzen hinweg gehen soll) oder eben &quot;einfach so&quot; (EVENT + CRITICAL_SECTION).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1200177</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1200177</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 31 Dec 2006 05:57:23 GMT</pubDate></item><item><title><![CDATA[Reply to Defekte Pipe on Sun, 31 Dec 2006 08:23:58 GMT]]></title><description><![CDATA[<p>ConnectNamedPipe wird nur auf der Serverseite verwendet!<br />
Der Client verwendet CreateFile und bei Bedarf WaitNamedPipe!<br />
Das hat ........... ja schon geschrieben!</p>
<p>Server:<br />
<a href="http://msdn2.microsoft.com/en-us/library/aa365588.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/aa365588.aspx</a><br />
Client:<br />
<a href="http://msdn2.microsoft.com/en-us/library/aa365592.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/aa365592.aspx</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1200188</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1200188</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 31 Dec 2006 08:23:58 GMT</pubDate></item><item><title><![CDATA[Reply to Defekte Pipe on Sun, 31 Dec 2006 12:45:33 GMT]]></title><description><![CDATA[<p>Vielen Dank für eure Antworten. Mit den beiden Beispielen sollte es funktionieren. Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1200257</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1200257</guid><dc:creator><![CDATA[Lot-Ionan]]></dc:creator><pubDate>Sun, 31 Dec 2006 12:45:33 GMT</pubDate></item></channel></rss>