ctype - python - long int too long to convert -
Question: problem:

> Traceback (most recent call last): File "C:\Users\Nutzer\Google
> Drive\Code\Code\memory_read.py", line 26, in byref(bytesRead))
> ctypes.ArgumentError: argument 2: : **long int too long to convert**

code:

    
    
    from ctypes import *
    from ctypes.wintypes import *
    
    PID = 4016
    
    address = 0x6C532407C
    
    OpenProcess = windll.kernel32.OpenProcess
    ReadProcessMemory = windll.kernel32.ReadProcessMemory
    CloseHandle = windll.kernel32.CloseHandle
    
    
    PROCESS_ALL_ACCESS = 0x1F0FFF
    
    datadummy = b'.'*200
    buffer = c_char_p(datadummy)
    bufferSize = len(buffer.value)
    bytesRead = c_ulong(0)
    
    processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, int(PID))
    
    ReadProcessMemory(processHandle, 
        address, 
        buffer, 
        bufferSize, 
        byref(bytesRead))
    
    CloseHandle(processHandle)
    

I tried to change the bytesRead = c_ulong(0) to some other ctypes, but no
success. Im on a Windows 8.1 System 64bit. I couldnt find any solution or
similiar problems after hours of searching. Does someone know whats wrong
here?


Answer: After a long time of fail and error I finally have an answer.

    
    
    from ctypes import *
    from ctypes.wintypes import *
    import ctypes
    
    OpenProcess = windll.kernel32.OpenProcess
    ReadProcessMemory = windll.kernel32.ReadProcessMemory
    CloseHandle = windll.kernel32.CloseHandle
    
    PROCESS_ALL_ACCESS = 0x1F0FFF
    
    pid = 2320
    address = 0x00C98FCC
    
    buffer = c_char_p(b"The data goes here")
    val = c_int()
    bufferSize = len(buffer.value)
    bytesRead = c_ulong(0)
    
    processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
    
    if ReadProcessMemory(processHandle, address, buffer, bufferSize, byref(bytesRead)):
        memmove(ctypes.byref(val), buffer, ctypes.sizeof(val))
    
        print("Success: " + str(val.value))
    else:
        print("Failed.")
    
    CloseHandle(processHandle)
    

