<?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[CallBack Funktion in injected dll]]></title><description><![CDATA[<p>hi,<br />
ich habe eine dll die nur eine callback funktion beinhaltet.<br />
die callback funktion soll mir Tastatureingaben abfangen.</p>
<p>Diese Dll injeziere ich in ein leere Anwendung die nur einen Dialog darstellt der nichts ausführt.</p>
<p>wenn ich die dll über die Anwendung mit LoadLibrary(&quot;MeineDll.dll&quot;) lade, wird die callbackfunktion einwandfrei ausgeführt und es werden alle tasten auf der tastatur anerkannt.</p>
<p>Wenn ich jetzt aber die dll durch eine andere Anwendung injeziere, wird zwar die dll in den anderen process geladen &amp; einmal ausgeführt. die callback funktion jedoch wird nicht ausgeführt.</p>
<p>wo liegt da das problem?<br />
weis jemand rat.</p>
<p>gruß lowfly</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/149740/callback-funktion-in-injected-dll</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 05:00:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/149740.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Jun 2006 20:30:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CallBack Funktion in injected dll on Thu, 08 Jun 2006 20:30:21 GMT]]></title><description><![CDATA[<p>hi,<br />
ich habe eine dll die nur eine callback funktion beinhaltet.<br />
die callback funktion soll mir Tastatureingaben abfangen.</p>
<p>Diese Dll injeziere ich in ein leere Anwendung die nur einen Dialog darstellt der nichts ausführt.</p>
<p>wenn ich die dll über die Anwendung mit LoadLibrary(&quot;MeineDll.dll&quot;) lade, wird die callbackfunktion einwandfrei ausgeführt und es werden alle tasten auf der tastatur anerkannt.</p>
<p>Wenn ich jetzt aber die dll durch eine andere Anwendung injeziere, wird zwar die dll in den anderen process geladen &amp; einmal ausgeführt. die callback funktion jedoch wird nicht ausgeführt.</p>
<p>wo liegt da das problem?<br />
weis jemand rat.</p>
<p>gruß lowfly</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074186</guid><dc:creator><![CDATA[LowFly]]></dc:creator><pubDate>Thu, 08 Jun 2006 20:30:21 GMT</pubDate></item><item><title><![CDATA[Reply to CallBack Funktion in injected dll on Fri, 09 Jun 2006 05:30:20 GMT]]></title><description><![CDATA[<p>LowFly schrieb:</p>
<blockquote>
<p>Wenn ich jetzt aber die dll durch eine andere Anwendung injeziere, wird zwar die dll in den anderen process geladen &amp; einmal ausgeführt. die callback funktion jedoch wird nicht ausgeführt.</p>
</blockquote>
<p>Du musst schon sagen &quot;WIE&quot; Du das machst... sonst kann man Dir schlecht helfen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074285</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074285</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Fri, 09 Jun 2006 05:30:20 GMT</pubDate></item><item><title><![CDATA[Reply to CallBack Funktion in injected dll on Fri, 09 Jun 2006 09:09:49 GMT]]></title><description><![CDATA[<p>ok,<br />
die Injectmethode sieht wie folgt aus.</p>
<p><strong>th32ProcessID</strong> wird via CreateToolhelp32Snapshot / Process32First / Process32Next ermittelt<br />
<strong>lpszDllPath</strong> ist der komplette Pfad zur dll.</p>
<pre><code>HMODULE	InjectByLoadLibraryA(DWORD th32ProcessID, LPCSTR lpszDllPath)
{
	HANDLE hThread;
	void*   pLibRemote;   
	DWORD   hLibModule;   // Base address of loaded module (==HMODULE);

	HMODULE hKernel32 = ::GetModuleHandleA(&quot;kernel32.dll&quot;);

	HANDLE hProcess = OpenProcessForRemoteExecute(th32ProcessID);

	pLibRemote = ::VirtualAllocEx( hProcess, NULL, (::strlen(lpszDllPath) + 1) * sizeof(char),
								   MEM_COMMIT, PAGE_READWRITE );

	::WriteProcessMemory( hProcess, pLibRemote, (LPVOID)lpszDllPath,
						  (::strlen(lpszDllPath) + 1) * sizeof(char), NULL );

	LPTHREAD_START_ROUTINE lpfn = (LPTHREAD_START_ROUTINE)::GetProcAddress(hKernel32, &quot;LoadLibraryA&quot;);
	if (lpfn == NULL)
		return NULL;

	hThread = ::CreateRemoteThread( hProcess, NULL, 0,lpfn,pLibRemote, 0, NULL );

	::WaitForSingleObject( hThread, INFINITE );

	::GetExitCodeThread( hThread, &amp;hLibModule );

	::VirtualFreeEx( hProcess, pLibRemote, 0, MEM_RELEASE );
	::CloseHandle( hThread );

	return (HMODULE)hLibModule;
}
</code></pre>
<p>der code in der dll sieht wie folgt aus.</p>
<pre><code>HHOOK xKeyHookHandle = NULL;

LRESULT CALLBACK xKeyboardHook( int code, WPARAM wParam, LPARAM lParam );
__declspec(dllexport) BOOL SetMyHook(HWND hWnd);

__declspec(dllexport) BOOL SetMyHook(HWND hWnd)
{

	DWORD ValveProc = GetWindowThreadProcessId(hWnd,NULL);

	xKeyHookHandle = SetWindowsHookEx(WH_KEYBOARD,
			    xKeyboardHook,
			    NULL,
			    ValveProc);

	if(xKeyHookHandle != NULL)
		 return TRUE;
	else
		return FALSE; 
}

LRESULT CALLBACK xKeyboardHook( int code, WPARAM wParam, LPARAM lParam )
{
    if(lParam &amp;0x80000000 || lParam &amp;0x40000000)
        return CallNextHookEx( xKeyHookHandle, code, wParam, lParam );

    // Check welcher Key gedrückt wird
    switch (wParam)
    {
        case VKEY_LEFT:
            add_log(&quot;Left pressed!&quot;);
        break;

        case VKEY_UP:
            add_log(&quot;Up pressed!&quot;);
        break;

        case VKEY_RIGHT:
            add_log(&quot;Right pressed!&quot;);
        break;

		case VKEY_DOWN:
            add_log(&quot;Down pressed!&quot;);
        break;

    }

    return CallNextHookEx( xKeyHookHandle, code, wParam, lParam );
}

BOOL APIENTRY DllMain( HINSTANCE hInstance, DWORD  dwReason, LPVOID lpReserved)
{

	HWND hWindow;

	switch(dwReason)
	{

		case DLL_PROCESS_ATTACH:

			DisableThreadLibraryCalls(hInstance);

			/////////////////////////////////////////////////////
			//Fülle die m_LogStruc bevor StartLog ausgeführt wird
			m_LogStruc.FileName = &quot;KeyHookLog.txt&quot;;
			m_LogStruc.LogStartText = &quot;Key Hook&quot;;
			StartLog();

			hWindow = HandleToWindow(&quot;TestInject.exe&quot;);

			if(!SetMyHook(hWindow))
				add_log(&quot;Handle auf Tasttatur fehlgeschlagen -&gt;0x%x&quot;,xKeyHookHandle);
			else
				add_log(&quot;Handle erfolgreich -&gt;0x%x &quot;,xKeyHookHandle);

				return true; //
		break;

		case DLL_THREAD_ATTACH:

		break; //
       				//

		case DLL_THREAD_DETACH:

		break;

		case DLL_PROCESS_DETACH:

		break;

	}//end switch(dwReason)

    return false;

}
</code></pre>
<p>es ist zu 100% sicher das mir HandleToWindow(&quot;TestInject.exe&quot;) das richtige Handle zurückgibt.</p>
<p>noch mal zur besseren verständigung.<br />
wenn ich in der OnInitDialog() Funktion der TestInject.exe die zu injezierende dll via LoadLibrary(...) lade funzt das einwandfrei und es wird mir in die logfile &quot;Left pressed&quot; usw. geschrieben.</p>
<p>Wenn ich jetzt aber die zu injezierende dll durch eine andere anwendung via <strong>InjectByLoadLibraryA</strong> lade. Wird mir die Dll in den Process injeziert(ich seh die dll wenn ich mir die Module der injezierten anwendung anschaue), AUCH schreibt es mir in die LogFile zb. Handle erfolgreich -&gt; 0xad2587ff es werden auch andere funktionen ausgeführt aber eben nur einmal und nicht dauerhaft.</p>
<p>das ist dann auch der grund weshalb ich glaube das die CallBack funktion nicht angesprochen wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074382</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074382</guid><dc:creator><![CDATA[LowFly]]></dc:creator><pubDate>Fri, 09 Jun 2006 09:09:49 GMT</pubDate></item></channel></rss>