c - 将 windows.h 与 main() 一起使用

标签 c winapi program-entry-point

我必须使用 main() 并调用 windows.h 中的函数。

以下代码希望使用 WinMain() 函数而不是 main()

#include <windows.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
    int vk_Shift = 16;

    while (1)
    {
        if (GetAsyncKeyState(vk_Shift) < 0)
        {
            printf("Shift is pressed\n");
        }
    }
}

错误

Error   1   error LNK2019: unresolved external symbol _WinMain@16 
referenced in function ___tmainCRTStartup   

Error   2   error LNK1120: 1 unresolved externals   

如何在 VS2013 中完成这项工作?

最佳答案

好的,伙计们,我明白了。

Felix Palmen的建议很有效。

... ... I guess configuring it as "console" application should do the trick.

所以,我所做的是将项目的首选项从 WIDOWS 更改为 CONSOLE

enter image description here

关于c - 将 windows.h 与 main() 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43921346/

相关文章:

c - Typedef、标记和未标记结构以及不兼容的指针类型

c - 为什么我收到 C2059 错误?

java - 通过公共(public)类选择 NEtbeans 中的主类时存在歧义

python __main__ 和 __init__ 正确使用

c++ - 哪个 winapi 函数允许我更改登录用户的密码?

c++ - 将 main 声明为被认为有害的 friend ?

python - 试图在一个类中编译内核,得到 "__init__() got an unexpected keyword argument ' kernel'”错误

c - 带空参数的函数

C++ 如何使用 _rmdir 删除文件?

c++ - 为什么消息框不阻塞线程?