As an example of form.... there's the DLL from that mouse hook project...
Code:
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x400
#pragma comment(linker, "/heap:128")
#define MMAPI __declspec(dllexport)
#include <windows.h>
/////////////////////////////////////////////////////////////////
// Handle double click
//
BOOL RevButtons = 0;
void SendClick(void)
{ if (!RevButtons)
{ mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); }
else
{ mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0); } }
/////////////////////////////////////////////////////////////////
// Mouse mod process
//
int lastdir = 1; // wheel tracker
BOOL mbutton = 0; // settings
BOOL hysterisis = 0;
HHOOK mmhook = NULL; // mouse hook handle
PMSLLHOOKSTRUCT mhs;
MMAPI LRESULT CALLBACK MouseTracker(int code, WPARAM wparm, LPARAM lparm)
{ if (code < 0)
return CallNextHookEx(mmhook,code,wparm,lparm);
// get struct address
mhs = (PMSLLHOOKSTRUCT)lparm;
// process the message
switch (wparm)
{ case WM_MBUTTONDOWN : // replace with lbutton dblclick
{ if (mbutton)
{ SendClick();
return 1; }
break; }
case WM_MBUTTONUP :
{ if (mbutton)
{ return 1; }
break; }
case WM_MOUSEWHEEL : // drop 1 msg on wheel reverses
{ if (hysterisis)
if (((lastdir < 0) && ((int)mhs->mouseData > 0)) ||
((lastdir > 0) && ((int)mhs->mouseData < 0)))
{ lastdir = (int)mhs->mouseData;
return 1; } } }
return CallNextHookEx(mmhook,code,wparm,lparm); }
/////////////////////////////////////////////////////////////////
// Enable features
//
MMAPI void WINAPI SetMButton(BOOL dblclk)
{ mbutton = (dblclk & 1); }
MMAPI void WINAPI SetMWheel(BOOL rollback)
{ hysterisis = (rollback & 1); }
/////////////////////////////////////////////////////////////////
// Set the windows hook
// if goforit = 1 hook is set, 0 to release
// Returns hook status 1 = active, 0 = not
//
HINSTANCE hdll; // dll handle
MMAPI BOOL WINAPI SetMHook(BOOL goforit)
{ if (goforit)
{ if (mmhook)
return 1;
mmhook = SetWindowsHookEx(WH_MOUSE_LL,&MouseTracker,hdll,0);
RevButtons = GetSystemMetrics(SM_SWAPBUTTON); }
else
{ if (mmhook)
{ if (UnhookWindowsHookEx(mmhook))
mmhook = NULL; } }
return (mmhook != NULL); }
/////////////////////////////////////////////////////////////////
// DLL entry point
//
BOOL APIENTRY DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
{ if (reason == DLL_PROCESS_ATTACH)
hdll = hinst;
return 1; }
Load the DLL... call the SetMHook function and the DLL is then injected into each process. There just wasn't any other way to do it.