<?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[#include in dll -&amp;gt; crash]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgender Header:</p>
<pre><code>#pragma once
#include &lt;windows.h&gt;
#define DLLEXPORT extern &quot;C&quot; __declspec(dllexport)

DLLEXPORT void SomeFunction();
BOOL APIENTRY DllMain (HINSTANCE, DWORD, LPVOID);
</code></pre>
<p>und folgender Code:</p>
<pre><code>#include &quot;DllMain.h&quot;

DLLEXPORT void SomeFunction()
{
    MessageBoxW(NULL, L&quot;Test&quot;, L&quot;Test&quot;, MB_OK);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    return TRUE;
}
</code></pre>
<p>.. lässt sich tadellos laden und SomeFunction() lässt sich von der Hostapplikation aus aufrufen.</p>
<p>Füge ich im Header aber folgende Zeile hinzu:</p>
<pre><code>#pragma once
#include &lt;windows.h&gt;

#include &lt;iostream&gt; &lt;----

#define DLLEXPORT extern &quot;C&quot; __declspec(dllexport)

DLLEXPORT void SomeFunction();
BOOL APIENTRY DllMain (HINSTANCE, DWORD, LPVOID);
</code></pre>
<p>... verabschiedet sich das komplette Programm beim Aufrufen der SomeFunction().<br />
Nebenbei wird die DLL um mehr als 200kb größer, was ich mir durch das einbinden der Cpp-RT erkläre.</p>
<p>Ich dachte immer, inkludierte Header sind nur für den Präprozessor bestimmt und können derlei Auswirkungen nicht haben.</p>
<p>Verwendet wird der GCC über MinGW 5.1.3.<br />
Ich würde den Vorgang gern debuggen, nur leider finde ich keine Hilfen zum Debuggen einer DLL mit dem GDB.</p>
<p>Hat jemand einen Rat für mich? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/209001/include-in-dll-gt-crash</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 03:18:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/209001.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Mar 2008 15:54:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to #include in dll -&amp;gt; crash on Tue, 25 Mar 2008 15:54:57 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgender Header:</p>
<pre><code>#pragma once
#include &lt;windows.h&gt;
#define DLLEXPORT extern &quot;C&quot; __declspec(dllexport)

DLLEXPORT void SomeFunction();
BOOL APIENTRY DllMain (HINSTANCE, DWORD, LPVOID);
</code></pre>
<p>und folgender Code:</p>
<pre><code>#include &quot;DllMain.h&quot;

DLLEXPORT void SomeFunction()
{
    MessageBoxW(NULL, L&quot;Test&quot;, L&quot;Test&quot;, MB_OK);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    return TRUE;
}
</code></pre>
<p>.. lässt sich tadellos laden und SomeFunction() lässt sich von der Hostapplikation aus aufrufen.</p>
<p>Füge ich im Header aber folgende Zeile hinzu:</p>
<pre><code>#pragma once
#include &lt;windows.h&gt;

#include &lt;iostream&gt; &lt;----

#define DLLEXPORT extern &quot;C&quot; __declspec(dllexport)

DLLEXPORT void SomeFunction();
BOOL APIENTRY DllMain (HINSTANCE, DWORD, LPVOID);
</code></pre>
<p>... verabschiedet sich das komplette Programm beim Aufrufen der SomeFunction().<br />
Nebenbei wird die DLL um mehr als 200kb größer, was ich mir durch das einbinden der Cpp-RT erkläre.</p>
<p>Ich dachte immer, inkludierte Header sind nur für den Präprozessor bestimmt und können derlei Auswirkungen nicht haben.</p>
<p>Verwendet wird der GCC über MinGW 5.1.3.<br />
Ich würde den Vorgang gern debuggen, nur leider finde ich keine Hilfen zum Debuggen einer DLL mit dem GDB.</p>
<p>Hat jemand einen Rat für mich? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480150</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480150</guid><dc:creator><![CDATA[IrgendeinGast]]></dc:creator><pubDate>Tue, 25 Mar 2008 15:54:57 GMT</pubDate></item><item><title><![CDATA[Reply to #include in dll -&amp;gt; crash on Tue, 25 Mar 2008 16:07:20 GMT]]></title><description><![CDATA[<p>DLL und EXE gegen die selbe runtime gelinkt?<br />
Derselbe Kompiler benutzt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480154</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480154</guid><dc:creator><![CDATA[simon.gysi]]></dc:creator><pubDate>Tue, 25 Mar 2008 16:07:20 GMT</pubDate></item><item><title><![CDATA[Reply to #include in dll -&amp;gt; crash on Tue, 25 Mar 2008 16:30:04 GMT]]></title><description><![CDATA[<p>Ja, Runtime und Compiler sind gleich.<br />
Hier der Loader:</p>
<pre><code>typedef void (*fpSomeFunction)(void);

...

        HMODULE hDll = LoadLibraryW(L&quot;test.dll&quot;);
        if (hDll == NULL)
        {
            std::cout &lt;&lt; &quot;Fehler1&quot; &lt;&lt; std::endl;
        }
        else
        {
            fpSomeFunction some = (fpSomeFunction)GetProcAddress(hDll, &quot;SomeFunction&quot;);
            if (some == NULL)
            {
                std::cout &lt;&lt; &quot;Fehler2&quot; &lt;&lt; std::endl;
            }
            else
            {
                some();
            }
        }
</code></pre>
<p>Ich versuche mal, try/catch einzubauen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480162</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480162</guid><dc:creator><![CDATA[IrgendeinGast]]></dc:creator><pubDate>Tue, 25 Mar 2008 16:30:04 GMT</pubDate></item><item><title><![CDATA[Reply to #include in dll -&amp;gt; crash on Tue, 25 Mar 2008 17:15:23 GMT]]></title><description><![CDATA[<p>Ok, hat sich gelöst.<br />
Es war eine Socketexception an einer anderen Codestelle, die zustande kam, weil die DLL eben durch die CRT an Größe zunahm.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480186</guid><dc:creator><![CDATA[IrgendeinGast]]></dc:creator><pubDate>Tue, 25 Mar 2008 17:15:23 GMT</pubDate></item><item><title><![CDATA[Reply to #include in dll -&amp;gt; crash on Tue, 22 Jul 2008 11:59:21 GMT]]></title><description><![CDATA[<p>Wie compilierst du das ganze? Also welche Zeile schreibst du in die cmd...</p>
<p>&quot;gcc -[...]&quot; ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1551595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1551595</guid><dc:creator><![CDATA[lippoliv]]></dc:creator><pubDate>Tue, 22 Jul 2008 11:59:21 GMT</pubDate></item><item><title><![CDATA[Reply to #include in dll -&amp;gt; crash on Wed, 23 Jul 2008 05:45:16 GMT]]></title><description><![CDATA[<pre><code>gcc -D DLL_EXPORT -shared -o dll.dll code.h
</code></pre>
<p>^^ habs gefunden</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1552098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1552098</guid><dc:creator><![CDATA[lippoliv]]></dc:creator><pubDate>Wed, 23 Jul 2008 05:45:16 GMT</pubDate></item></channel></rss>