On Fri, Oct 6, 2017 at 10:06 PM, Michael C <mysecretrobotfact...@gmail.com> wrote: > like this? > > buffer = ctypes.byref(ctypes.create_string_buffer(4))
No, the buffer is the array created by create_string_buffer, which you pass byref(). In the following example I create a `test` buffer that contains "spam", and I use the pseudo-handle from GetCurrentProcess with ReadProcessMemory to read this buffer into a target `buffer`. It's silly to do this in the current process, but it's just an example. import ctypes from ctypes.wintypes import HANDLE, LPVOID kernel32 = ctypes.WinDLL('kernel32', use_last_error=True) SIZE_T = ctypes.c_size_t LPSIZE_T = ctypes.POINTER(SIZE_T) kernel32.GetCurrentProcess.restype = HANDLE kernel32.ReadProcessMemory.argtypes = (HANDLE, LPVOID, LPVOID, SIZE_T, LPSIZE_T) hProcess = kernel32.GetCurrentProcess() test = ctypes.create_string_buffer(b'spam') address = ctypes.addressof(test) buffer = ctypes.create_string_buffer(4) nread = SIZE_T() success = kernel32.ReadProcessMemory(hProcess, address, ctypes.byref(buffer), ctypes.sizeof(buffer), ctypes.byref(nread)) if not success: raise ctypes.WinError(ctypes.get_last_error()) print(buffer[:]) _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor