Im trying to write a console screen buffer, but i keep getting different errors pointing at the LPDWORD variable no matter what values i assign to it
#include<iostream>
#include<Windows.h>
using namespace std;
int main()
{
COORD cell{0, 0};
LPDWORD NumberOfCharsWritten = 0;
wchar_t* screen = new wchar_t[80 * 30];
HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ, FILE_SHARE_WRITE, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
SetConsoleActiveScreenBuffer(hConsole);
DWORD dwBytesWriten = 0;
while (true)
{
screen[10 * 80 15] = L'P';
WriteConsoleOutputCharacter(hConsole, screen, 80 * 30, cell, NumberOfCharsWritten);
}
}
CodePudding user response:
You are passing a NULL pointer to WriteConsoleOutputCharacter(), but the pointer needs to point to an actual DWORD instead.
Declare a DWORD variable and use the & operator to get a pointer to that DWORD:
DWORD NumberOfCharsWritten = 0;
...
WriteConsoleOutputCharacter(..., &NumberOfCharsWritten);
