how use VirtualAlloc()?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//..........
RECT d;
        GetClientRect(HWNDConsoleWindow, &d);
        int ConsoleWidth = d.right - d.left;
        int ConsoleHeight = d.bottom  - d.top;

        int PixelsCount = ConsoleWidth * ConsoleHeight * sizeof(unsigned int);
        BitInfo.bmiHeader.biSize = sizeof(BitInfo.bmiHeader);
        BitInfo.bmiHeader.biWidth = ConsoleWidth;
        BitInfo.bmiHeader.biHeight = ConsoleHeight;
        BitInfo.bmiHeader.biPlanes = 1;
        BitInfo.bmiHeader.biBitCount = 32;
        BitInfo.bmiHeader.biCompression = BI_RGB;

        if(Pixels) VirtualFree(Pixels,0, MEM_RELEASE);
        Pixels = VirtualAlloc(0, PixelsCount,MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);

        unsigned int *PixelColors = (unsigned int) Pixels;
        std::cout <<sizeof(PixelColors) << "\t";
//............ 

the 'PixelsCount' is 1843200.... so why the 'sizeof(PixelColors)' is 8? same is go for 'sizeof(Pixels)'
sizeof(PixelColors) gives the number of bytes used for the type int *. ie pointer to int. For 64 bit compile this will be 8. This is nothing to do with the number of allocated memory bytes pointed to by PixelColors. sizeof() gives the size of the type.
how i test if the 1843200 space is added to the pointer?
i review the code and now 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
39
40
41
42
43
44
void *BufferMemory;
    BITMAPINFO BitInfo;
    HWND HWNDConsoleWindow = GetConsoleWindow();
    HDC HDCConsoleWindow = GetDC(HWNDConsoleWindow);
RECT rect;
    GetClientRect(HWNDConsoleWindow, &rect);
    int ConsoleWidth = rect.right - rect.left;
    int ConsoleHeight = rect.bottom - rect.top;


    BitInfo.bmiHeader.biSize = sizeof(BitInfo.bmiHeader);
    BitInfo.bmiHeader.biWidth = ConsoleWidth;
    BitInfo.bmiHeader.biHeight = ConsoleHeight;
    BitInfo.bmiHeader.biPlanes = 1;
    BitInfo.bmiHeader.biBitCount = 32;
    BitInfo.bmiHeader.biCompression = BI_RGB;

    int BufferSize = ConsoleWidth * ConsoleHeight * sizeof(unsigned int);

    if(BufferMemory) VirtualFree(BufferMemory, 0,MEM_RELEASE);
    BufferMemory = VirtualAlloc(0, BufferSize,MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
    unsigned int *PixelColors = (unsigned int) BufferMemory;
do
    {
        for(int y=0; y<ConsoleHeight; y++)
        {
            for(int x=0, i=0; x<ConsoleWidth; x++)
            {

                if(i<GetLineDots.size() && GetLineDots[i].PosX == x &&  GetLineDots[i].PosY==y )
                {
                    PixelColors[y*ConsoleWidth + x] = RGB(0,255,0);
                    //MessageBox(NULL, "error", "error", MB_OK);
                    i++;
                }
                else
                {
                    PixelColors[y*ConsoleWidth + x] = RGB(0,0,255);
                }

            }
        }
        StretchDIBits(HDCConsoleWindow,0,0,ConsoleWidth, ConsoleHeight, 0,0, ConsoleWidth,ConsoleHeight, BufferMemory, &BitInfo,DIB_RGB_COLORS, SRCCOPY );
    }while(!GetAsyncKeyState(VK_ESCAPE));

thanks so much for all to all
Topic archived. No new replies allowed.