<?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[SOLVED - DLL steigt in VS2015 aus]]></title><description><![CDATA[<p>Hallo.</p>
<p>Mit folgender Funktion konnte ich bisher in VS2013 alle printf Ausgabe in eine Console úmleiten, da der Code teil einer DLL ist, welche ich in C# nutze.<br />
Gleich vorweg, ich kann leider diese DLL nicht mit dem C# Projekt debuggen, weil die DLL eine statische Bibliothek ausführt, welche ohne Basic Runtime Checks kompiliert wurde, so dass ich das für meine DLL auch so einstellen musste.</p>
<pre><code>#define COMMANDLINEOUTPUT_H

int AllocConsoleOutputFkt(){
	int hConHandle;
	long lStdHandle;
	FILE *fp;

	AllocConsole();

	lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);

	fp = _fdopen(hConHandle, &quot;w&quot;);
	*stdout = *fp;

	setvbuf(stdout, NULL, _IONBF, 0);

	return 0;
}

extern &quot;C&quot; __declspec(dllexport) int AllocConsoleOutputParalution(){ return AllocConsoleOutputFkt(); }
</code></pre>
<p>Jetzt arbeite ich mit VS2015 und sobald ich die DLL ausführe, steigt das C# Programm ohne Fehlermeldung aus. Ich konnte durch auskommentieren herausbekommen, dass das Programm in Zeile 14, also fp = _fopen... aussteigt.</p>
<p>Hat jemand eine Idee, woran das liegen kann? Ich kann leider keinen Haltepunkt setzen und checken, welchen Wert hConHandle hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/335588/solved-dll-steigt-in-vs2015-aus</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 10:35:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/335588.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 28 Nov 2015 03:27:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SOLVED - DLL steigt in VS2015 aus on Sat, 28 Nov 2015 04:15:50 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Mit folgender Funktion konnte ich bisher in VS2013 alle printf Ausgabe in eine Console úmleiten, da der Code teil einer DLL ist, welche ich in C# nutze.<br />
Gleich vorweg, ich kann leider diese DLL nicht mit dem C# Projekt debuggen, weil die DLL eine statische Bibliothek ausführt, welche ohne Basic Runtime Checks kompiliert wurde, so dass ich das für meine DLL auch so einstellen musste.</p>
<pre><code>#define COMMANDLINEOUTPUT_H

int AllocConsoleOutputFkt(){
	int hConHandle;
	long lStdHandle;
	FILE *fp;

	AllocConsole();

	lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);

	fp = _fdopen(hConHandle, &quot;w&quot;);
	*stdout = *fp;

	setvbuf(stdout, NULL, _IONBF, 0);

	return 0;
}

extern &quot;C&quot; __declspec(dllexport) int AllocConsoleOutputParalution(){ return AllocConsoleOutputFkt(); }
</code></pre>
<p>Jetzt arbeite ich mit VS2015 und sobald ich die DLL ausführe, steigt das C# Programm ohne Fehlermeldung aus. Ich konnte durch auskommentieren herausbekommen, dass das Programm in Zeile 14, also fp = _fopen... aussteigt.</p>
<p>Hat jemand eine Idee, woran das liegen kann? Ich kann leider keinen Haltepunkt setzen und checken, welchen Wert hConHandle hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477390</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Sat, 28 Nov 2015 04:15:50 GMT</pubDate></item><item><title><![CDATA[Reply to SOLVED - DLL steigt in VS2015 aus on Sat, 28 Nov 2015 03:39:22 GMT]]></title><description><![CDATA[<p><a href="http://stackoverflow.com/questions/9020790/using-stdin-with-an-allocconsole" rel="nofollow">http://stackoverflow.com/questions/9020790/using-stdin-with-an-allocconsole</a></p>
<p>Was macht</p>
<pre><code class="language-cpp">AllocConsole();

freopen(&quot;CONIN$&quot;, &quot;r&quot;, stdin); 
freopen(&quot;CONOUT$&quot;, &quot;w&quot;, stdout); 
freopen(&quot;CONOUT$&quot;, &quot;w&quot;, stderr);
</code></pre>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477391</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sat, 28 Nov 2015 03:39:22 GMT</pubDate></item><item><title><![CDATA[Reply to SOLVED - DLL steigt in VS2015 aus on Sat, 28 Nov 2015 04:15:20 GMT]]></title><description><![CDATA[<p>Funktioniert super.</p>
<p>Anbei der Code, wie man von C# aus den stdout einer dll, die man über System.Runtime.Interopt Service aufruft, auf eine console bekommt. Ist wunderbar zum debuggen.</p>
<p>CommandLineOutput.h</p>
<pre><code>#define COMMANDLINEOUTPUT_H

int AllocConsoleOutputFkt(){
	int hConHandle;
	long lStdHandle;
	FILE *fpIn;
	FILE *fpOut;
	FILE *fpErr;

	AllocConsole();

	//fpIn = freopen(&quot;CONIN$&quot;, &quot;r&quot;, stdin);
	fpOut = freopen(&quot;CONOUT$&quot;, &quot;w&quot;, stdout);
	//fpErr = freopen(&quot;CONOUT$&quot;, &quot;w&quot;, stderr);

	*stdout = *fpOut;

	setvbuf(stdout, NULL, _IONBF, 0);

	return 0;
}

extern &quot;C&quot; __declspec(dllexport) int AllocConsoleOutputParalution(){ return AllocConsoleOutputFkt(); }
</code></pre>
<p>In C# dann einfach die Funktion zum Aufrufen einmal ausführen:</p>
<pre><code>[DllImport(&lt;Filename of the dll library *.dll&gt;, EntryPoint = &quot;AllocConsoleOutputParalution&quot;, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
        public static extern void AllocConsoleOutput();
</code></pre>
<p>Und schon ploppt ein Commandwindow auf und man sieht die Konsolenanwendung durchlaufen.</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2477392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477392</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Sat, 28 Nov 2015 04:15:20 GMT</pubDate></item><item><title><![CDATA[Reply to SOLVED - DLL steigt in VS2015 aus on Sat, 28 Nov 2015 18:17:56 GMT]]></title><description><![CDATA[<p>Die Zeile <code>*stdout = *fpOut;</code> ist nicht nötig.</p>
<p>Der Returnwert von <code>freopen</code> ist NULL (im Fehlerfall) oder sonst genau das was man übergeben hat.<br />
Wenn <code>freopen</code> fehlschlägt crasht dein Programm also.<br />
Ansonsten macht es sinngemäss <code>*stdout = *stdout</code> - also nix sinnvolles.</p>
<p>Und da man FILE structs als &quot;opaque&quot; behandeln sollte (=nur mit dem FILE* Zeiger und den stdio Funktionen arbeiten, niemals den Zeiger dereferenzieren), würde ich die Zeile lieber wegmachen.</p>
<p>Was das <code>setvbuf</code> angeht bin ich mir nicht sicher ob das nötig ist. Kann aber vermutlich auch nicht schaden. Bzw. wenn &quot;line buffered&quot; für dich schon zu viel ist, dann ist es natürlich nötig.</p>
<p>Ich würde also eher das vorschlagen</p>
<pre><code class="language-cpp">int AllocConsoleOutputFkt()
{
    AllocConsole();
    if (freopen(&quot;CONOUT$&quot;, &quot;w&quot;, stdout))
        return setvbuf(stdout, NULL, _IONBF, 0);
    else
        return errno;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2477442</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2477442</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sat, 28 Nov 2015 18:17:56 GMT</pubDate></item></channel></rss>