I've scrapped my old answer since it was irrelevant. The new on also used OpenCV (since I'm trying to display an OpenCV image) but it can be adapted to any framework.
The core code is where it takes a memory address address
, and the number of bytes to read through numrows
, numcols
, and byte_size
and reads those bytes into a buffer. I'm sure you can adapt that portion of the code for your own needs.
#include "stdafx.h"
#include <windows.h>
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace std;
using namespace cv;
void imshow_debug(const LPCVOID address, const int numrows, const int numcols, const int type, const int byte_size, const int step, const string windows_title)
{
// Initialize
unsigned long PID;
SIZE_T read_bytes = 0;
// Allocate space for the image
const int bytes_to_read = numrows*numcols*byte_size;
uchar *image_data = new uchar[bytes_to_read];
Mat Image(numrows,numcols,type,image_data,step);
// Get the handle and PID
HWND handle = FindWindowA(0, windows_title.c_str());
if (!FindWindowA(0, windows_title.c_str()))
{
printf("Window %s not found!", windows_title);
exit(0);
}
GetWindowThreadProcessId(handle, &PID); /* Get windows PID from a window handle */
HANDLE WindowsProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, false, PID);
// Read the image
ReadProcessMemory(WindowsProcessHandle,address,image_data,bytes_to_read,&read_bytes);
if(bytes_to_read != read_bytes)
{
cout<<"Could not read entire image"<<endl;
exit(0);
}
// Display the image
namedWindow("Image");
imshow("Image",Image);
waitKey();
// Clean up
CloseHandle(WindowsProcessHandle);
delete[]image_data;
}
int main(int argc, char* argv[])
{
imshow_debug((LPVOID)0x03af0370,300,300,CV_64F,sizeof(double),2400,"C:\\Documents and Settings\\jacobm\\My Documents\\Visual Studio 2005\\Projects\\Head\\debug\\SSR_VideoComp.exe");
return 0;
}