I'm not really sure what this is doing in this thread, but here's the problem:
Code:
Const
NumberOfBytes = 2;
Banshee = 159;
GetMem(buf,1);
buf^ := Chr(Banshee);
WriteProcessMemory(HandleWindow,ptr(Address),buf,NumberOfBytes,write);
FreeMem(buf);
You're putting a single byte in the buffer, but you're writing two bytes. It looks like the second byte of the buffer has a random (but consistent?)
89 in it. Thus the two bytes written are 159:89, or hexadecimal 9F:59. On a "little-endian" processor, that's the decimal 22943 you're getting.
The solution is to set the second byte of the buffer to zero before writing it. That means you'll have to make your buffer two bytes long, too.