<?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[Qt crash on attach dll]]></title><description><![CDATA[<p dir="auto">Hello! So i've got the following code going inside a dll (c++)</p>
<pre><code>int myLibraryExec() {
	char appName[] = "Project";
	char *an = appName;
	int argc = 0;
	QApplication app(argc, &amp;an);
	app.exec();
	return 0;
}

int mainFunction() {
	if (console.allocateConsole()) {
		std::cout &lt;&lt; "Successful Injection!" &lt;&lt; std::endl;
	}
	std::cout &lt;&lt; "Trying" &lt;&lt; std::endl;
	int app = myLibraryExec();
	std::cout &lt;&lt; "xd" &lt;&lt; std::endl;
	return 0;
}


BOOL APIENTRY DllMain(HMODULE hModule,
	DWORD  ul_reason_for_call,
	LPVOID lpReserved
)
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
		hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mainFunction, (LPVOID)hModule, 0, NULL);
		if (hThread == NULL) {
			return 0;
		}
	}
	else if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
	}
	else if (ul_reason_for_call == DLL_PROCESS_DETACH) {
	}
	else if (ul_reason_for_call == DLL_THREAD_DETACH) {
	}
	return TRUE;
}


</code></pre>
<p dir="auto">It compiles fine, but when i try to attach it to a process to make sure it works, it crashes at the QApplication line, it never gets to exec().</p>
<p dir="auto">Any help would be appreciated.</p>
]]></description><link>https://forum.qt.io/topic/95851/qt-crash-on-attach-dll</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 20:11:09 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/95851.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Oct 2018 21:36:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Qt crash on attach dll on Wed, 24 Oct 2018 21:08:53 GMT]]></title><description><![CDATA[<p dir="auto">Again: what about the stack trace ?</p>
]]></description><link>https://forum.qt.io/post/488803</link><guid isPermaLink="true">https://forum.qt.io/post/488803</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 24 Oct 2018 21:08:53 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Wed, 24 Oct 2018 00:21:00 GMT]]></title><description><![CDATA[<p dir="auto">Anyone has an idea?...</p>
]]></description><link>https://forum.qt.io/post/488616</link><guid isPermaLink="true">https://forum.qt.io/post/488616</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 24 Oct 2018 00:21:00 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 23:42:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hskoglund">@<bdi>hskoglund</bdi></a> yes, sadly it does.</p>
<pre><code>#include "stdafx.h"
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string&gt; 

#include "memoryManager.h"
#include "consoleManager.h"
#include "Addresses.h"

#include &lt;QtWidgets/QApplication&gt;
#include &lt;QtWidgets/QPushbutton&gt;
#include &lt;QtWidgets/QMainWindow&gt;

// DEFENITIONS
#define _CRT_SECURE_NO_DEPRECATE

HANDLE hThread;

memoryManager memory = memoryManager();
consoleManager console = consoleManager();
static struct Data {
	int argc = 1;
	char *argv[2] = { strdup("dummy"), {} };
	QApplication app{ argc, argv };//
	QMainWindow win;//
} *d;

static void startup() {
	d = new Data;
	d-&gt;win.show();
	d-&gt;app.processEvents();
}

static void shutdown() {
	delete d;
}

int mainFunction() {
	if (console.allocateConsole()) {
		std::cout &lt;&lt; "Successful Attachment!" &lt;&lt; std::endl;
	}
	startup();
	return 0;
} 


BOOL APIENTRY DllMain(HMODULE hModule,
	DWORD  ul_reason_for_call,
	LPVOID lpReserved
)
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
		startup();
		//hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mainFunction, (LPVOID)hModule, 0, NULL);
		//if (hThread == NULL) {
		//	return 0;
		//}
	}
	else if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
	}
	else if (ul_reason_for_call == DLL_PROCESS_DETACH) {
		shutdown();
	}
	else if (ul_reason_for_call == DLL_THREAD_DETACH) {
	}
	return TRUE;
}


</code></pre>
<p dir="auto">yes it does...</p>
]]></description><link>https://forum.qt.io/post/488614</link><guid isPermaLink="true">https://forum.qt.io/post/488614</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 23 Oct 2018 23:42:30 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 23:32:54 GMT]]></title><description><![CDATA[<p dir="auto">If you skip calling CreateThread(), remove the hThread variable and just call startup() does it still crash?</p>
]]></description><link>https://forum.qt.io/post/488613</link><guid isPermaLink="true">https://forum.qt.io/post/488613</guid><dc:creator><![CDATA[hskoglund]]></dc:creator><pubDate>Tue, 23 Oct 2018 23:32:54 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 23:05:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hskoglund">@<bdi>hskoglund</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a>  heyhey, so i tried that but i can't seem to figure out where MainWindow comes from, so i turned it into a QMainWindow</p>
<p dir="auto">But it still crashes...</p>
<p dir="auto">Doesn't matter whether i call it inside the CreateThread or outside of it...</p>
<pre><code>static struct Data {
	int argc = 1;
	char *argv[2] = { strdup("dummy"), {} };
	QApplication app{ argc, argv };
	QMainWindow win;
} *d;

static void startup() {
	d = new Data;
	d-&gt;win.show();
	d-&gt;app.processEvents();
}

static void shutdown() {
	delete d;
}

int mainFunction() {
	if (console.allocateConsole()) {
		std::cout &lt;&lt; "Successful Attachment!" &lt;&lt; std::endl;
	}
	startup();
	return 0;
}


BOOL APIENTRY DllMain(HMODULE hModule,
	DWORD  ul_reason_for_call,
	LPVOID lpReserved
)
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
		hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mainFunction, (LPVOID)hModule, 0, NULL);

		if (hThread == NULL) {
			return 0;
		}
	}
	else if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
	}
	else if (ul_reason_for_call == DLL_PROCESS_DETACH) {
	}
	else if (ul_reason_for_call == DLL_THREAD_DETACH) {
	}
	return TRUE;
}
</code></pre>
<p dir="auto">and</p>
<pre><code>static struct Data {
	int argc = 1;
	char *argv[2] = { strdup("dummy"), {} };
	QApplication app{ argc, argv };
	QMainWindow win;
} *d;

static void startup() {
	d = new Data;
	d-&gt;win.show();
	d-&gt;app.processEvents();
}

static void shutdown() {
	delete d;
}

int mainFunction() {
	if (console.allocateConsole()) {
		std::cout &lt;&lt; "Successful Attachment!" &lt;&lt; std::endl;
	}
	return 0;
}


BOOL APIENTRY DllMain(HMODULE hModule,
	DWORD  ul_reason_for_call,
	LPVOID lpReserved
)
{
	if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
		hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)mainFunction, (LPVOID)hModule, 0, NULL);
 	        startup();
		if (hThread == NULL) {
			return 0;
		}
	}
	else if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
	}
	else if (ul_reason_for_call == DLL_PROCESS_DETACH) {
	}
	else if (ul_reason_for_call == DLL_THREAD_DETACH) {
	}
	return TRUE;
}


</code></pre>
]]></description><link>https://forum.qt.io/post/488611</link><guid isPermaLink="true">https://forum.qt.io/post/488611</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 23 Oct 2018 23:05:50 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 22:28:05 GMT]]></title><description><![CDATA[<p dir="auto">Hi, one problem though: you're launching a QApplication inside your DLL's DLLMain using a CreateThread call and that is a risky business at best, usually it crashes :-( See more <a href="https://docs.microsoft.com/en-us/windows/desktop/Dlls/dynamic-link-library-best-practices" target="_blank" rel="noopener noreferrer nofollow ugc">here</a> about what is supported by Windows inside a DLLMain</p>
]]></description><link>https://forum.qt.io/post/488605</link><guid isPermaLink="true">https://forum.qt.io/post/488605</guid><dc:creator><![CDATA[hskoglund]]></dc:creator><pubDate>Tue, 23 Oct 2018 22:28:05 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 21:55:03 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Did you check the stack trace ?</p>
<p dir="auto">You should check the solution provided in this <a href="https://stackoverflow.com/a/11056698/5843716" target="_blank" rel="noopener noreferrer nofollow ugc">stackoverflow thread</a>.</p>
]]></description><link>https://forum.qt.io/post/488599</link><guid isPermaLink="true">https://forum.qt.io/post/488599</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 23 Oct 2018 21:55:03 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 21:49:18 GMT]]></title><description><![CDATA[<p dir="auto">worth a try, but didnt work lol <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a></p>
]]></description><link>https://forum.qt.io/post/488596</link><guid isPermaLink="true">https://forum.qt.io/post/488596</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 23 Oct 2018 21:49:18 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 21:48:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mehodin">@<bdi>Mehodin</bdi></a><br />
Humor me:</p>
<pre><code>int argc = 1;
char *argv[] = { appname, 0 };
QApplication app(argc, argv);
</code></pre>
]]></description><link>https://forum.qt.io/post/488595</link><guid isPermaLink="true">https://forum.qt.io/post/488595</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 23 Oct 2018 21:48:50 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 21:44:07 GMT]]></title><description><![CDATA[<p dir="auto">thank you, yeah <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> i had already tried that haha. tried it again after i replied to make sure.</p>
<pre><code>int mainFunction() {
	if (console.allocateConsole()) {
		std::cout &lt;&lt; "Successful Attachment!" &lt;&lt; std::endl;
	}
	char appName[] = "Project";
	char *an = appName;
	int argc = 1;
	QApplication app(argc, &amp;an);
	app.exec();
	return 0;
}

</code></pre>
]]></description><link>https://forum.qt.io/post/488594</link><guid isPermaLink="true">https://forum.qt.io/post/488594</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 23 Oct 2018 21:44:07 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 21:42:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mehodin">@<bdi>Mehodin</bdi></a><br />
That was quick to test!  Gotta start somewhere... :)</p>
]]></description><link>https://forum.qt.io/post/488593</link><guid isPermaLink="true">https://forum.qt.io/post/488593</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 23 Oct 2018 21:42:06 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 21:41:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> that crashes aswel</p>
]]></description><link>https://forum.qt.io/post/488592</link><guid isPermaLink="true">https://forum.qt.io/post/488592</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 23 Oct 2018 21:41:33 GMT</pubDate></item><item><title><![CDATA[Reply to Qt crash on attach dll on Tue, 23 Oct 2018 21:41:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mehodin">@<bdi>Mehodin</bdi></a><br />
<a href="http://doc.qt.io/qt-5/qapplication.html#QApplication" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qapplication.html#QApplication</a></p>
<blockquote>
<p dir="auto">In addition, argc must be greater than zero</p>
</blockquote>
<p dir="auto">? Did you mean <code>int argc = 1;</code> ?</p>
]]></description><link>https://forum.qt.io/post/488591</link><guid isPermaLink="true">https://forum.qt.io/post/488591</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 23 Oct 2018 21:41:08 GMT</pubDate></item></channel></rss>