GetCurrentConsoleFont未在作用域中声明,我做错了什么? [英] GetCurrentConsoleFont not declared in scope, what I do wrong?
问题描述
一开始我有:
#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;
}
并且未记录的函数SetConsoleFont
可以工作,但是GetCurrentConsoleFont
编译失败,提示它未在此范围内声明.
And undocumented function SetConsoleFont
works, but GetCurrentConsoleFont
fails at compilation saying that it was not declared in this scope.
-更改为自持代码.
推荐答案
GetCurrentConsoleFont至少是在NT4 +上导出的,MinGW标头一定是错误的.
GetCurrentConsoleFont is exported on NT4+ at least, the MinGW headers must be wrong.
尝试在您的#include之后添加此代码:
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);
(每次看到PSOMETYPE作为参数时,通常都会在堆栈上分配一个SOMETYPE结构,并将指向该结构的指针作为参数传递)
(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)
这篇关于GetCurrentConsoleFont未在作用域中声明,我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!