GetCurrentConsoleFont not declared in scope, what I do wrong?

↘锁芯ラ 提交于 2019-12-08 07:51:25

问题


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.


回答1:


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)




回答2:


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.



来源:https://stackoverflow.com/questions/8866402/getcurrentconsolefont-not-declared-in-scope-what-i-do-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!