OiO.lk Blog C# WriteConsoleOutputCharacter not working properly
C#

WriteConsoleOutputCharacter not working properly


I was trying to set a couple functions to work with the windows console. The function WriteConsoleOutputCharacter() from the Window API is not printing the full string like it used to, at first i thought it was the way i was doing it, but then i tried to do it out of the function on a new file, and i get the same result:

The code:

#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>


int main() {
    HANDLE console = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    SetConsoleActiveScreenBuffer(console);
    wchar_t* data = L"Hello World";
    DWORD bytes = 0;
    COORD pos = {0,0};

    while (1) {
        WriteConsoleOutputCharacter(console, data, strlen(data), pos, &bytes);
    }

    CloseHandle(console);

    return 0;
}

The output: H (the first character of the string).

It does not print when out of a loop.

NOTE: The charset on the preprocessor definition is set to unicode.



You need to sign in to view this answers

Exit mobile version