Solved[Help] Timer in C++ DLL

Posts 1–5 of 5 · Page 1 of 1
[Help] Timer in C++ DLL
Hello, i want to do a 10 second timer before using WriteProcessMemory in my dll hack, but i dont know how to make it work, im getting a error


Code:
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
DWORD WINAPI LoopFunction( LPVOID lpParam )
{
	HANDLE gta3 = GetCurrentProcess();
	SetTimer(HWND hWnd , 10000, 1);       // ERROR: expected ")", and type name is not allowed
	BYTE StandingON[] = {0x00, 0x00, 0x00};
	WriteProcessMemory(gta3,(void*)(0x05F2D54),&StandingON,1, 0);
	Sleep(200);
	return 0;
}
BOOL WINAPI DllMain (HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
{
    if (dwAttached == DLL_PROCESS_ATTACH) {
        CreateThread(NULL,0,&LoopFunction,NULL,0,NULL);
    }
    return 1;
}


i dont know how to fix

please provide me a example or full fix :/
Jesus, learn some C++ before copy pasting code and hacking it together.

You don't need to use wpm from an injected DLL, you can access the memory directly using pointers.
Your wpm call is only writing one byte when it looks like you want to write 3.
You haven't defined hWnd, so it won't have any useful value.
And if you just want to wait 10 seconds before using the wpm, you can just use "Sleep(10000);"

Edit:

Code:
#include <Windows.h>

DWORD WINAPI LoopFunction()
{
	char nop "\x00";
	DWORD address = 0x05F2D54;

        Sleep(10000);
        for(int i = 0; i < 3; i++){
            *(char*)(address + i) = nop;
        }
	return 0;
}
BOOL WINAPI DllMain (HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
{
    if (dwAttached == DLL_PROCESS_ATTACH) {
        CreateThread(NULL,0,&LoopFunction,NULL,0,NULL);
    }
    return true;
}
Wrote that from my phone so it might have an error, but that's the general idea for how you would want to do it.
Now go learn C++.
Quote Originally Posted by Nimboso View Post
Jesus, learn some C++ before copy pasting code and hacking it together.

You don't need to use wpm from an injected DLL, you can access the memory directly using pointers.
Your wpm call is only writing one byte when it looks like you want to write 3.
You haven't defined hWnd, so it won't have any useful value.
And if you just want to wait 10 seconds before using the wpm, you can just use "Sleep(10000);"

Edit:

Code:
#include <Windows.h>

DWORD WINAPI LoopFunction()
{
	char nop "\x00";
	DWORD address = 0x05F2D54;

        Sleep(10000);
        for(int i = 0; i < 3; i++){
            *(char*)(address + i) = nop;
        }
	return 0;
}
BOOL WINAPI DllMain (HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
{
    if (dwAttached == DLL_PROCESS_ATTACH) {
        CreateThread(NULL,0,&LoopFunction,NULL,0,NULL);
    }
    return true;
}
Wrote that from my phone so it might have an error, but that's the general idea for how you would want to do it.
Now go learn C++.
no is 0x90 I believe if not, It's just 90.

Also, You don't need to write it as a char, you could just write it as a byte :P
Quote Originally Posted by Silent View Post


no is 0x90 I believe if not, It's just 90.

Also, You don't need to write it as a char, you could just write it as a byte :P
Oh damn you're right, its been a while since I've actually written a patching function lol, normally I just use my already written class.

Good call about the byte, though the compiler would fix it either way, it would help with readability, thanks.
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us