VS-2019 的编译错误

Compilation errors with VS-2019

下面的代码无法编译。我收到两个错误:

    _TCHAR* pStrAddress;
    ... some stuff here...
    IN_ADDR  sa;
    InetPton(AF_INET, pStrAddress, &sa);
    *pIP = sa.S_un.S_addr;

1) IN_ADDR --> 错误 C2065: 'AF_INET': 未声明的标识符

2) InetPton(...) --> C3861:'InetPton':未找到标识符

我的配置如下:

继续,从编辑器中,可以访问符号,但 preprosessor/compiler 似乎没有相同的路径。显然我遗漏了一些最可能显而易见的东西。 非常感谢您的帮助。

谢谢!

找到了! 我创建了一个小项目,仅以 post 感兴趣的代码作为代码示例,一切都编译正常。所以,首先必须有一些显而易见的事情。然后它击中了我!:预编译头不是第一个include。

感谢大家的帮助!

不好代码:

    #include <windows.h>
    #include <ws2tcpip.h>
    #include <stdlib.h>

    #include "pch.h"   <-- this must be the first include!!!!!!

代码:

    #include "pch.h"   <-- ok, happy compiler and developer  ;)

    #include <windows.h>
    #include <ws2tcpip.h>
    #include <stdlib.h>