public void WriteProcessMemory(IntPtr MemoryAddress, byte[] bytesToWrite, out int bytesWritten) { IntPtr ptrBytesWritten; uint oldProtect; bool res = ProcessMemoryReaderApi.VirtualProtectEx(m_hProcess, MemoryAddress, new UIntPtr((uint)bytesToWrite.Length), 0x40, out oldProtect); int code; code = Marshal.GetLastWin32Error(); ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten); code = Marshal.GetLastWin32Error(); bytesWritten = ptrBytesWritten.ToInt32(); }