<?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[Problem mit einbinden einer DLL]]></title><description><![CDATA[<p>Wie der Titel schon sagt, klappt das einbinden einer DLL in ein anderen Process irgendwie nicht.</p>
<p>Hier der Code:</p>
<pre><code>int main()
{
HANDLE hThread;
DWORD procId;

void* pLibRemote;
char DLL[]=&quot;aHook.dll&quot;;

HWND hWnd=FindWindow(NULL,&quot;Unbenannt - Editor&quot;);

GetWindowThreadProcessId(hWnd,&amp;procId);

HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,procId);

pLibRemote= VirtualAllocEx(hProcess,NULL,sizeof(DLL),MEM_COMMIT,PAGE_READWRITE);

WriteProcessMemory(hProcess,pLibRemote,(void*)DLL,sizeof(DLL),NULL);

hThread=CreateRemoteThread(hProcess,NULL,0,(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(&quot;Kernel32&quot;),&quot;LoadLibraryA&quot;),pLibRemote,0,NULL);

WaitForSingleObject(hThread,INFINITE);

MessageBox(NULL,&quot;Target Application closed&quot;,&quot;END&quot;,MB_OK);
return 0;
}
</code></pre>
<p>Die MessageBox öffnet sich direkt obwohl sie erst nach dem beenden des Zielprocesses kommen sollte. Und die DLL wird auch nicht eingebunden. Kann jemand helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/145283/problem-mit-einbinden-einer-dll</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 02:23:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/145283.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Apr 2006 14:28:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit einbinden einer DLL on Wed, 26 Apr 2006 14:28:38 GMT]]></title><description><![CDATA[<p>Wie der Titel schon sagt, klappt das einbinden einer DLL in ein anderen Process irgendwie nicht.</p>
<p>Hier der Code:</p>
<pre><code>int main()
{
HANDLE hThread;
DWORD procId;

void* pLibRemote;
char DLL[]=&quot;aHook.dll&quot;;

HWND hWnd=FindWindow(NULL,&quot;Unbenannt - Editor&quot;);

GetWindowThreadProcessId(hWnd,&amp;procId);

HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,procId);

pLibRemote= VirtualAllocEx(hProcess,NULL,sizeof(DLL),MEM_COMMIT,PAGE_READWRITE);

WriteProcessMemory(hProcess,pLibRemote,(void*)DLL,sizeof(DLL),NULL);

hThread=CreateRemoteThread(hProcess,NULL,0,(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(&quot;Kernel32&quot;),&quot;LoadLibraryA&quot;),pLibRemote,0,NULL);

WaitForSingleObject(hThread,INFINITE);

MessageBox(NULL,&quot;Target Application closed&quot;,&quot;END&quot;,MB_OK);
return 0;
}
</code></pre>
<p>Die MessageBox öffnet sich direkt obwohl sie erst nach dem beenden des Zielprocesses kommen sollte. Und die DLL wird auch nicht eingebunden. Kann jemand helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1045741</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1045741</guid><dc:creator><![CDATA[pThunk]]></dc:creator><pubDate>Wed, 26 Apr 2006 14:28:38 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit einbinden einer DLL on Wed, 26 Apr 2006 14:34:32 GMT]]></title><description><![CDATA[<p>Eine Idee was schiefgehen könnte habe ich nicht, aber ein Ansatz wäre evtl. mal die ganzen Rückgabewerte auf Fehlercodes zu überprüfen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1045746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1045746</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 26 Apr 2006 14:34:32 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit einbinden einer DLL on Wed, 26 Apr 2006 14:52:18 GMT]]></title><description><![CDATA[<p>Hm bringt mich auch nicht weiter. Ich krieg zumindest kein error.</p>
<p>[code]<br />
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)<br />
{<br />
HANDLE hThread;</p>
<p>DWORD procId;</p>
<p>HWND hWnd=FindWindow(NULL,&quot;Unbenannt - Editor&quot;);<br />
if(!hWnd)<br />
MessageBox(NULL,&quot;Fenster konnte nicht gefunden werden&quot;,&quot;ERROR&quot;,MB_ICONERROR|MB_OK);</p>
<p>if(!GetWindowThreadProcessId(hWnd,&amp;procId))<br />
MessageBox(NULL,&quot;Process Id konnte nicht ermittelt werden&quot;,&quot;ERROR&quot;,MB_ICONERROR|MB_OK);</p>
<p>HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,procId);<br />
if(!hProcess)<br />
MessageBox(NULL,&quot;Process konnte nicht geöffnet werden&quot;,&quot;ERROR&quot;,MB_ICONERROR|MB_OK);</p>
<p>void* pLibRemote;</p>
<p>char DLL[]=&quot;aHook.dll&quot;;</p>
<p>pLibRemote= VirtualAllocEx(hProcess,NULL,sizeof(DLL),MEM_COMMIT,PAGE_READWRITE);</p>
<p>if(!pLibRemote)<br />
MessageBox(NULL,&quot;Platz für dll konnte nicht allokiert werden&quot;,&quot;ERROR&quot;,MB_ICONERROR|MB_OK);</p>
<p>if(!WriteProcessMemory(hProcess,pLibRemote,(void*)DLL,sizeof(DLL),NULL))<br />
MessageBox(NULL,&quot;Das schreiben in den Process ist fehlgeschlagen&quot;,&quot;ERROR&quot;,MB_ICONERROR|MB_OK);</p>
<p>hThread=CreateRemoteThread(hProcess,NULL,0,(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(&quot;Kernel32.dll&quot;),&quot;LoadLibraryA&quot;),pLibRemote,0,NULL);<br />
if(!hThread)<br />
MessageBox(NULL,&quot;Remote Thread konnte nicht erstellt werden&quot;,&quot;ERROR&quot;,MB_ICONERROR|MB_OK);</p>
<p>WaitForSingleObject(hThread,INFINITE);<br />
MessageBox(NULL,&quot;Target Application closed&quot;,&quot;END&quot;,MB_OK);</p>
<p>return TRUE;<br />
}</p>
<p>Bin verzweifelt :(.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1045765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1045765</guid><dc:creator><![CDATA[pThunk]]></dc:creator><pubDate>Wed, 26 Apr 2006 14:52:18 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit einbinden einer DLL on Wed, 26 Apr 2006 15:47:13 GMT]]></title><description><![CDATA[<p>Wie sieht'n die DLL aus? Hab beim Überfliegen auch nix gefunden, aber ich hab hier noch code rumliegen den ich irgendwann mal geschrieben hab, vielleicht hilft dir das ja.</p>
<pre><code class="language-cpp">int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	PSTR pszLibFileRemote;
	PTHREAD_START_ROUTINE pfnThreadRtn;
	HANDLE hRemoteThread;

	PSTR pszLibFile = &quot;ep2Inject.dll&quot;;
	int nSize;

	memset( &amp;si, 0, sizeof(si) );
	memset( &amp;pi, 0, sizeof(pi) );
	si.cb = sizeof(si);

	if( !CreateProcess( &quot;editplus.exe&quot;, lpCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &amp;si, &amp;pi ) )
	{
		MessageBox( NULL, &quot;CreateProcess failed&quot;, &quot;Error&quot;, MB_OK );
		return 1;
	}

	// wait until EditPlus2 is ready
	// make sure all windows have been initialized before we
	// attempt to inject our dll.
	WaitForInputIdle( pi.hProcess, INFINITE );

	// allocate memory in target process address space
	nSize = lstrlen(pszLibFile) + 1;
	pszLibFileRemote = (PSTR) VirtualAllocEx( pi.hProcess, NULL, nSize, MEM_COMMIT, PAGE_READWRITE );

	if( pszLibFileRemote == NULL )
	{
		MessageBox( NULL, &quot;VirtualAllocEx failed&quot;, &quot;Error&quot;, MB_ICONERROR );
		CloseHandle( pi.hProcess );
		CloseHandle( pi.hThread );
		return 1;
	}

	// copy DLL name into address space of target process
	if( !WriteProcessMemory( pi.hProcess, pszLibFileRemote, pszLibFile, nSize, NULL ) )
	{
		MessageBox( NULL, &quot;WriteProcessMemory failed&quot;, &quot;Error&quot;, MB_ICONERROR );
		VirtualFreeEx( pi.hProcess, pszLibFileRemote, 0, MEM_RELEASE );
		CloseHandle( pi.hProcess );
		CloseHandle( pi.hThread );
		return 1;
	}

	// figure out real address of LoadLibraryA.
	// this assumes Kernel32.dll has the same base address in every process.
	pfnThreadRtn = (PTHREAD_START_ROUTINE) GetProcAddress( GetModuleHandle(&quot;Kernel32&quot;), &quot;LoadLibraryA&quot; );
	if( pfnThreadRtn == NULL )
	{
		MessageBox( NULL, &quot;GetProcAddress failed&quot;, &quot;Error&quot;, MB_ICONERROR );
		VirtualFreeEx( pi.hProcess, pszLibFileRemote, 0, MEM_RELEASE );
		CloseHandle( pi.hProcess );
		CloseHandle( pi.hThread );
		return 1;
	}

	// create the remote thread
	// this triggers a DLL_PROCESS_ATTACH in the injected dll
	hRemoteThread = CreateRemoteThread( pi.hProcess, NULL, 0, pfnThreadRtn, pszLibFileRemote, 0, NULL );
	if( hRemoteThread == NULL )
	{
		MessageBox( NULL, &quot;CreateRemoteThread failed&quot;, &quot;Error&quot;, MB_ICONERROR );
		VirtualFreeEx( pi.hProcess, pszLibFileRemote, 0, MEM_RELEASE );
		CloseHandle( pi.hProcess );
		CloseHandle( pi.hThread );
		return 1;
	}

	// wait for remote thread to finish
	WaitForSingleObject( hRemoteThread, INFINITE );

	// free allocated memory
	if( pszLibFileRemote != NULL )
		VirtualFreeEx( pi.hProcess, pszLibFileRemote, 0, MEM_RELEASE );

	// wait for Editplus2 to finish
//	WaitForSingleObject( pi.hProcess, INFINITE );
	CloseHandle( pi.hProcess );
	CloseHandle( pi.hThread );

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1045802</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1045802</guid><dc:creator><![CDATA[WebNubbi]]></dc:creator><pubDate>Wed, 26 Apr 2006 15:47:13 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit einbinden einer DLL on Wed, 26 Apr 2006 16:08:35 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=403" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=4" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1045818</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1045818</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Wed, 26 Apr 2006 16:08:35 GMT</pubDate></item></channel></rss>