GetCurrentConsoleFont not declared in scope, what

2019-06-08 03:37发布

at the beginning I have:

#include <sstream>
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <string>
#define _WIN32_WINNT 0x500 //tells that this is win 2000 or higher, without GetConsoleWindow would not work
#include <windows.h>

using namespace std;

int main() {
  PCONSOLE_FONT_INFO lpConsoleCurrentFont;
  GetCurrentConsoleFont(GetStdHandle(STD_OUTPUT_HANDLE), false,  lpConsoleCurrentFont);
  return 0;
}

And undocumented function SetConsoleFont works, but GetCurrentConsoleFont fails at compilation saying that it was not declared in this scope.

-- edit: changed to self sustained code.

2条回答
一夜七次
2楼-- · 2019-06-08 04:11

GetCurrentConsoleFont is exported on NT4+ at least, the MinGW headers must be wrong.

Try adding this code after your #include's:

#ifdef __cplusplus
extern "C" {
#endif
BOOL WINAPI GetCurrentConsoleFont(HANDLE hConsoleOutput,BOOL bMaximumWindow,PCONSOLE_FONT_INFO lpConsoleCurrentFont);
#ifdef __cplusplus
}
#endif

Your code is also wrong, it should be:

CONSOLE_FONT_INFO ConsoleFontInfo;
GetCurrentConsoleFont(GetStdHandle(STD_OUTPUT_HANDLE), false,  &ConsoleFontInfo);

(Any time you see PSOMETYPE as a parameter you usually allocate a SOMETYPE struct on the stack and pass a pointer to this struct as the parameter)

查看更多
劫难
3楼-- · 2019-06-08 04:12

Hans comment above is correct. GetCurrentConsoleFont is not defined in wincon.h. Add the following lines to wincon.h to get this functionality:

BOOL WINAPI GetCurrentConsoleFont(HANDLE, BOOL, PCONSOLE_FONT_INFO );

COORD WINAPI GetConsoleFontSize( HANDLE, DWORD );

GetConsoleFontSize was also missing.

查看更多
登录 后发表回答