Memory Write Problem!?!

Hi, Im having a problem, the code dont give me a problem but this allway happen "Cannot open process." how do i fix it? im running Windows 7 64bit im code on Dev-C++

tnx in 4hand ^^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  #include <stdio.h>
#include <windows.h>

int main()
{
    int newValue = 500;
    HWND hWnd = FindWindow(0, "Kalkylatorn");

    if (hWnd == 0) {
        fprintf(stderr, "Cannot find window.");
    } else {
        DWORD pId;
        GetWindowThreadProcessId(hWnd, &pId);
        HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);

        if (!hProc) {
            fprintf(stderr, "Cannot open process.");
        } else {
            int isSuccessful = WriteProcessMemory(hProc, (LPVOID)0x000AFCC4, &newValue, (DWORD)sizeof(newValue), NULL);

            if (isSuccessful > 0) {
                puts("Process memory written.");
            } else {
                fprintf(stderr, "Cannot write process memory.");
            }

            CloseHandle(hProc);
        }
    }
    getchar();
    return 0;
}
Use GetLastError function to obtain more about the problem

http://msdn.microsoft.com/en-us/library/windows/desktop/ms679360%28v=vs.85%29.aspx

Maybe it's a problem with access rights.
If you just want to write to the process memory try PROCESS_VM_WRITE (if the process allows that).

See
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684880%28v=vs.85%29.aspx
Topic archived. No new replies allowed.