Making This Work As DLL
Ok so you've maybe seen my other thread. But now, I want to make it a DLL that you have to inject, for learning purposes. So the old code works and writes memory fine in a console application. Is there something wrong with my DLL code that'd make it not work? It injects with Winject but the effect is not apparent in game at all. I tried commenting out VirtualProtectEx just in case for some reason that might affect it, but that didn't work. Any ideas?
Code:
// main.cpp
#include "main.h"
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if(fdwReason == DLL_PROCESS_ATTACH)
{
byte NoSpread[] = {
0x74,
0x15
};
byte NoRecoil[] = {
0x75,
0x08
};
HWND hWnd = FindWindow(NULL, TEXT("Call of Duty 4"));
DWORD pId;
GetWindowThreadProcessId(hWnd, &pId);
HANDLE hProc = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, pId);
WriteProcessMemory(hProc, (void*)0x00416C7B, &NoSpread, 2, 0);
WriteProcessMemory(hProc, (void*)0x0041A7BD, &NoRecoil, 2, 0);
VirtualProtectEx(hProc, (void*)0x00416C7B, 2, 0x01, (DWORD*)&NoSpread);
VirtualProtectEx(hProc, (void*)0x0041A7BD, 2, 0x01, (DWORD*)&NoRecoil);
CloseHandle(hProc);
return 0;
}
}
Code:
// main.h
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
