I'm getting a problem with the function:
SetCurrentConsoleFontEx because GetCurrentConsoleFontEx return bad values.
I get a structure with GetCurrentConsoleFontEx, then I pass the same to SetCurrentConsoleFontEx.
I get a error. The same with visual studio 2013 not.
Please, help for fix this.
output of executable compiled with tcc (note that the values printed are different from the visual studio):
GetCurrentConsoleFontEx ok
nFont:4198533
dwFontSize.X:64 dwFontSize.Y:64
FontFamily:48
FontWeight:400
SetCurrentConsoleFontEx error
Error:87
output of executable compiled with visual studio 2013:
GetCurrentConsoleFontEx ok
nFont:6
dwFontSize.X:8 dwFontSize.Y:12
FontFamily:48
FontWeight:400
SetCurrentConsoleFontEx ok
I asume that with tcc SetCurrentConsoleFontEx fails because GetCurrentConsoleFontEx return bad values for the nFont. In this case: 4198533 also dwFontSize.X:64 dwFontSize.Y:64
c source:
#include <windows.h>
#include <stdio.h>
// in visual studio 2013 not define _CONSOLE_FONT_INFOEX
typedef struct _CONSOLE_FONT_INFOEX {
ULONG cbSize;
DWORD nFont;
COORD dwFontSize;
UINT FontFamily;
UINT FontWeight;
WCHAR FaceName[LF_FACESIZE];
} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
int main()
{
LONG err;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFOEX cfiex;
cfiex.cbSize = sizeof(CONSOLE_FONT_INFOEX);
err = GetCurrentConsoleFontEx(hOut, FALSE, &cfiex);
if ((LONG)0 == err) {
printf("GetCurrentConsoleFontEx error\n");
printf("Error:%d\n", GetLastError());
return 1;
}
else {
printf("GetCurrentConsoleFontEx ok\n");
}
printf("nFont:%d\n", cfiex.nFont);
printf("dwFontSize.X:%d dwFontSize.Y:%d\n", cfiex.dwFontSize.X, cfiex.dwFontSize.Y);
printf("FontFamily:%d\n", cfiex.FontFamily);
printf("FontWeight:%d\n", cfiex.FontWeight);
err = SetCurrentConsoleFontEx(hOut, FALSE, &cfiex);
if ((LONG)0 == err) {
printf("SetCurrentConsoleFontEx error\n");
printf("Error:%d\n", GetLastError());
return 1;
}
else {
printf("SetCurrentConsoleFontEx ok\n");
}
getchar();
return 0;
}
The problem is with the function GetCurrentConsoleFontEx not with the SetCurrentConsoleFontEx, because this Works with tiny cc:
it prints:
nFont:6
dwFontSize.X:8 dwFontSize.Y:12
FontFamily:48
FontWeight:400
SetCurrentConsoleFontEx ok
#include <windows.h>
#include <stdio.h>
typedef struct _CONSOLE_FONT_INFOEX {
ULONG cbSize;
DWORD nFont;
COORD dwFontSize;
UINT FontFamily;
UINT FontWeight;
WCHAR FaceName[LF_FACESIZE];
} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
int main()
{
LONG err;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFOEX cfiex;
cfiex.cbSize = sizeof(CONSOLE_FONT_INFOEX);
cfiex.nFont = 6;
cfiex.dwFontSize.X = 8;
cfiex.dwFontSize.Y = 12;
cfiex.FontFamily = 48;
cfiex.FontWeight = 400;
lstrcpyW(cfiex.FaceName, L"Terminal");
printf("nFont:%d\n", cfiex.nFont);
printf("dwFontSize.X:%d dwFontSize.Y:%d\n", cfiex.dwFontSize.X, cfiex.dwFontSize.Y);
printf("FontFamily:%d\n", cfiex.FontFamily);
printf("FontWeight:%d\n", cfiex.FontWeight);
err = SetCurrentConsoleFontEx(hOut, FALSE, &cfiex);
if ((LONG)0 == err) {
printf("SetCurrentConsoleFontEx error\n");
printf("Error:%d\n", GetLastError());
return 1;
}
else {
printf("SetCurrentConsoleFontEx ok\n");
}
getchar();
return 0;
}