c++ - PfCreateInterface 返回错误 120(未实现)

标签 c++ c windows winapi ip

我需要为 Windows 创建一个简单的 IP 过滤程序;但是,我在使相关的 API 调用正常工作时遇到了问题。下面是一个小示例,演示了 PfCreateInterface 是如何失败的。它返回 120,这是系统错误代码 ERROR_CALL_NOT_IMPLEMENTED。我在 Windows 10 上运行该程序。

#include <windows.h>
#include <Iphlpapi.h>
#include <Fltdefs.h>
#include <iostream>

#pragma comment(lib, "Iphlpapi.lib")

int main()
{
    INTERFACE_HANDLE hInterface;
    PFFORWARD_ACTION action = PF_ACTION_FORWARD;

    DWORD errorCode = PfCreateInterface(0,
        action,
        action,
        FALSE,
        TRUE,
        &hInterface);

    std::cout << "errorCode = " << errorCode << std::endl;    
}

有人可以解释为什么它失败了吗?如果我不能在 Windows 10 上使用它,您知道替代 API 是什么吗?

最佳答案

Microsoft's documentation很清楚:

PfCreateInterface is available for use in the operating systems listed in the Requirements section.

“要求部分中列出的”Windows 版本是 Windows Server 2003 或 Windows 2000 Server。

所以这个 API 调用基本上已经过时了。文档建议使用 the Windows Filtering Platform management functions相反。

关于c++ - PfCreateInterface 返回错误 120(未实现),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58559521/

相关文章:

c++ - LPPICTURE 在哪里定义的?

C++ zip 可变参数模板

c++ - 无法在单独的函数中调用 ifstream

c - 使用 3D 动态数组的函数中出现段错误

java - 找不到 ElasticSearch Lucene UnicodeUtil

c - 变量.c :4:1: error: expected declaration specifiers or '...' before '(' token

c++ - Qt和串口编程

c++ - 使用 SDL2 指定 OpenGL 版本

c - 在 linux 终端中无法检测到退格键,K&R 1.10 练习

c - 为什么 C == 对于相等的字符串返回 true?