foo()
{
HWND hWnd;
while((hWnd = FindWindow(null, "Untitled - Notepad")) == NULL) // Keep waiting for a window with 'Untitled - Notepad' to appear
Sleep(100);
DWORD pID;
GetWindowThreadProcessId(hWnd, &pID); // Get the process ID from the window handle
HANDLE pHandle = OpenProcess(PROCESS_VM_WRITE, FALSE, pID);
if(pHandle == NULL)
return; // Couldn't get a process handle.
// Replace 0xDEADBEEF with the real address and replace the 5 with the real byte array size.
BYTE[] data = { 0x00, 0x11, 0x55, 0x10, 0x42 };
WriteProcessMemory(pHandle, (LPVOID)0xDEADBEEF, &data, 5, NULL);
CloseHandle(pHandle); // Close the handle if we don't need it anymore.
}