未定义对GetConsoleWindow的引用
我正在尝试使用以下命令获取控制台窗口的句柄:未定义对GetConsoleWindow的引用,c,winapi,windows-console,C,Winapi,Windows Console,我正在尝试使用以下命令获取控制台窗口的句柄: #include <Windows.h> #include <stdio.h> #include <stdlib.h> #define NTDDI_WIN7 as 0x06010000 #define _WIN32_WINNT as 0x0500 int main(int argc, char *argv[]) { HWND self = GetConsoleWindow(); /* some
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#define NTDDI_WIN7 as 0x06010000
#define _WIN32_WINNT as 0x0500
int main(int argc, char *argv[]) {
HWND self = GetConsoleWindow();
/* some more code */
return 0;
}
#包括
#包括
#包括
#将NTDDI_WIN7定义为0x06010000
#将_WIN32_WINNT定义为0x0500
int main(int argc,char*argv[]){
HWND self=GetConsoleWindow();
/*还有代码吗*/
返回0;
}
我按照文档中的说明进行操作,但我仍然得到:
未定义对“GetConsoleWindow”的引用
您必须在输入库列表中包含kernel32.lib。在包含
windows.h
之前,您可能必须使用定义。在包含windows.h之前,您确实需要定义,并且将NTDDI\u WIN7定义为0x06010000
的语法不正确。链接的文档非常清楚地表明,宏会影响头的解析,因此在包含它们之前必须可用。您的意思是定义NTDDI\u版本
,而不是它可以定义为的常量值之一(即\define NTDDI\u VERSION NTDDI\u WIN7
)。如果目标是特定的service pack,请定义此宏。否则,让标题根据\u WIN32\u WINNT
的值定义它。对于后者,除非您实际上是针对古老的Windows 2000(即\u WIN32\u WINNT\u WIN2K
,即0x0500),否则您将希望使用更新的版本,或SDK中的默认值。Windows 2000只是wincon.h标题中的GetConsoleWindow
所需的最低版本。另外:需要删除#define
s中的“as”