Click here to Skip to main content
15,885,366 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: PrintWindow Pin
Ernest Laurentin10-Mar-08 8:40
Ernest Laurentin10-Mar-08 8:40 
GeneralMy Dll Injector Code Does Not Work-, listing processes and injecting .dll- Help! Pin
Mike Yurgalavage10-Mar-08 4:05
Mike Yurgalavage10-Mar-08 4:05 
GeneralRe: My Dll Injector Code Does Not Work-, listing processes and injecting .dll- Help! Pin
Stephen Hewitt10-Mar-08 15:11
Stephen Hewitt10-Mar-08 15:11 
GeneralRe: My Dll Injector Code Does Not Work-, listing processes and injecting .dll- Help! Pin
Mike Yurgalavage10-Mar-08 15:49
Mike Yurgalavage10-Mar-08 15:49 
GeneralRe: My Dll Injector Code Does Not Work-, listing processes and injecting .dll- Help! Pin
Stephen Hewitt10-Mar-08 15:51
Stephen Hewitt10-Mar-08 15:51 
GeneralRe: My Dll Injector Code Does Not Work-, listing processes and injecting .dll- Help! Pin
Mike Yurgalavage10-Mar-08 16:43
Mike Yurgalavage10-Mar-08 16:43 
GeneralRe: My Dll Injector Code Does Not Work-, listing processes and injecting .dll- Help! Pin
Stephen Hewitt10-Mar-08 17:57
Stephen Hewitt10-Mar-08 17:57 
GeneralRe: My Dll Injector Code Does Not Work-, listing processes and injecting .dll- Help! Pin
Stephen Hewitt10-Mar-08 17:43
Stephen Hewitt10-Mar-08 17:43 
Try something like this:

EXE:
// InjectDLL.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
using namespace std;
 
#ifdef __cplusplus
extern "C"
{
#endif
 
void __stdcall SetHook();
 
#ifdef __cplusplus
}
#endif

int main(int argc, char* argv[])
{
	SetHook();
 
	return 0;
}


DLL:
// InjectMe.cpp : Defines the entry point for the DLL application.
//
 
#include "stdafx.h"
#include <tchar.h>
 
HMODULE g_hMod = NULL;
 
#pragma comment(linker, "/SECTION:.shared,RWS")
#pragma data_seg(".shared")
HHOOK g_hHook = NULL;
#pragma data_seg()
 
LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam)
{
	LRESULT res = CallNextHookEx(NULL, code, wParam, lParam);
 
	static bool bDone = false;
	if (bDone && res==HC_ACTION)
	{
		bDone = true;
 
		UnhookWindowsHookEx(g_hHook);
 
		::MessageBox(NULL, _T("Hello"), _T("Hello"), MB_OK);
	}
 
	return res;
}
 
#ifdef __cplusplus
extern "C"
{
#endif
 
void __stdcall SetHook()
{
	// Find Notepad's window.
	HWND hwnd = FindWindow(_T("Notepad"), NULL);
	if (hwnd == NULL)
	{
		return;
	}
 
	// Get the main thread's ID.
	DWORD ThreadId = GetWindowThreadProcessId(hwnd, NULL);
 
	// Hook it.
	HHOOK g_hHook = SetWindowsHookEx(
				WH_GETMESSAGE,					// int idHook
				reinterpret_cast<HOOKPROC>(&GetMsgProc),	// HOOKPROC lpfn
				g_hMod,						// HINSTANCE hMod
				ThreadId					// DWORD dwThreadId
				);
	if (g_hHook == NULL)
	{
		return;
	}


	// Post a "do nothing" message to Notepad so our hook is called.
	PostMessage(hwnd, WM_NULL, 0, 0);
}
 
#ifdef __cplusplus
}
#endif
 
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		g_hMod = reinterpret_cast<HMODULE>(hModule);
		DisableThreadLibraryCalls(g_hMod);
		break;
	}

    return TRUE;
}


Steve

modified on Tuesday, March 11, 2008 12:14 AM

GeneralRe: My Dll Injector Code Does Not Work-, listing processes and injecting .dll- Help! Pin
Mike Yurgalavage11-Mar-08 3:41
Mike Yurgalavage11-Mar-08 3:41 
GeneralRe: My Dll Injector Code Does Not Work-, listing processes and injecting .dll- Help! Pin
Mike Yurgalavage12-Mar-08 6:29
Mike Yurgalavage12-Mar-08 6:29 
Generalcreate an toolbar,not in any window or dialog box.. Pin
preeti sharma10-Mar-08 2:29
preeti sharma10-Mar-08 2:29 
QuestionRe: create an toolbar,not in any window or dialog box.. Pin
Maximilien10-Mar-08 2:50
Maximilien10-Mar-08 2:50 
Questionabout lable font size Pin
savitri10-Mar-08 2:08
savitri10-Mar-08 2:08 
GeneralRe: about lable font size Pin
David Crow10-Mar-08 3:02
David Crow10-Mar-08 3:02 
GeneralVariable Static text box Pin
neha.agarwal2710-Mar-08 1:53
neha.agarwal2710-Mar-08 1:53 
GeneralRe: Variable Static text box Pin
ThatsAlok10-Mar-08 1:59
ThatsAlok10-Mar-08 1:59 
GeneralRe: Variable Static text box Pin
Cedric Moonen10-Mar-08 2:01
Cedric Moonen10-Mar-08 2:01 
GeneralRe: Variable Static text box Pin
jhwurmbach10-Mar-08 2:03
jhwurmbach10-Mar-08 2:03 
GeneralRe: Variable Static text box Pin
Hamid_RT10-Mar-08 3:09
Hamid_RT10-Mar-08 3:09 
GeneralRe: Variable Static text box Pin
ThatsAlok10-Mar-08 9:11
ThatsAlok10-Mar-08 9:11 
GeneralRe: Variable Static text box Pin
Hamid_RT10-Mar-08 22:35
Hamid_RT10-Mar-08 22:35 
GeneralRe: Variable Static text box Pin
ThatsAlok11-Mar-08 1:49
ThatsAlok11-Mar-08 1:49 
GeneralRe: Variable Static text box Pin
Hamid_RT11-Mar-08 19:33
Hamid_RT11-Mar-08 19:33 
GeneralShellExecute(0, _T("open"), _T(strUrl.c_str()), 0, 0,SW_HIDE); displays the window Pin
ptr_Electron10-Mar-08 1:45
ptr_Electron10-Mar-08 1:45 
GeneralRe: ShellExecute(0, _T("open"), _T(strUrl.c_str()), 0, 0,SW_HIDE); displays the window Pin
jhwurmbach10-Mar-08 1:56
jhwurmbach10-Mar-08 1:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.