DIB to string (How to?)

Hi. Just to let you all know, we are working on a DLL to return a string containing pixel data from an area of the screen. It's very simple, cycles through a for loop and returns a single string, with each color seperated by a " ".

Now, I am very bad at C++, but I managed to get it to work with GetPixel. But that is very slow, so I want to use DIB functions. Unfortunately that is very complicated...

Here is the code we have so far (Yes I know there is a potential memory problem, but it works.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#define GMString extern "C" __declspec(dllexport) char*
#include <string>
#include <stdlib.h>
#include <windows.h>
using namespace std;

GMString getPixels(double x, double y, double w, double h) {
COLORREF c;
HDC hDC;
hDC = GetDC(NULL);
string stri;
double size = (w)*(h);
int size2 = int(size);
char temp1[size2];
string stri2;


int x2 = int (x);
int y2 = int (y);
int w2 = int (w);
int h2 = int (h);
int i = 0;

for (int xx=x2; xx<x+w2; xx++) {
for (int yy=y2; yy<y+h2; yy++) {
c=(GetPixel(hDC, xx, yy));
itoa(c, temp1, 10);
stri += temp1;
stri += " ";
i+=1;
}
}

ReleaseDC(GetDesktopWindow(), hDC);


return const_cast<char *>(stri.c_str());
} 


Now I tried adding the DIB stuff with no luck. I have no idea if I'm using the right DIB functions, and I don't have a clue what the stuff on MSDN means (such as tydef structs and what I'm supposed to do with GetDIBits.

The experimental code is this but I get an error on the line with &PBITMAPINFO,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;


int GetDIBits(
hDC,
CreateCompatibleBitmap(hDC,GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)),
1,
100,
NULL,
&PBITMAPINFO,
0
);
Topic archived. No new replies allowed.