简体   繁体   English

MinGW - Header 不完整<netfw.h></netfw.h>

[英]MinGW - Header incomplete <netfw.h>

i am developing a networked application in C++ that should be able to add a rule to the windows firewall.我正在C++中开发一个网络应用程序,它应该能够向 windows 防火墙添加规则。 I am following this example using the MingW g++ compiler .我正在使用MingW g++ 编译器来关注这个示例 The other examples are working without a problem, but this particular example won't work.其他示例都可以正常工作,但这个特定示例不起作用。

The exact problem i am facing, that NetFwRule is not defined in the <netfw.h> header provided by MinGW.我面临的确切问题是, NetFwRule未在 MinGW 提供的<netfw.h> header 中定义。 When i try to compile that example with MSVC (in Visual Studio) it works flawlessly, since NetFwRule is defined in the header provided by MSVS.当我尝试使用 MSVC(在 Visual Studio 中)编译该示例时,它可以完美运行,因为NetFwRule是在 MSVS 提供的 header 中定义的。 However it is absolutely neccessary for the project to use the MinGW g++ compiler.但是,该项目绝对有必要使用 MinGW g++ 编译器。

This particular code snippet as shown in the example link won't work, since NetFwRule is not defined:示例链接中显示的此特定代码段将不起作用,因为NetFwRule

// Create a new Firewall Rule object.
hr = CoCreateInstance(
       __uuidof(NetFwRule), // <- Problem in MinGW g++, but in MSVC it just works
       NULL,
       CLSCTX_INPROC_SERVER,
       __uuidof(INetFwRule),
       (void**)&pFwRule
);

So what needs to be done in order to make this work using MinGW?那么为了使用 MinGW 完成这项工作需要做些什么呢?

FYI: I have MinGW 32 bit with posix thread for the i686 architecture installed.仅供参考:我为 i686 架构安装了带有 posix 线程的 MinGW 32 位。

g++ --version gives g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0 g++ --version提供g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0

The error message is: 'NetFwRule' was not declared in this scope错误消息是: 'NetFwRule' was not declared in this scope

In fact it really is not declared, since the <netfw.h> of MinGW does not declare NetFwRule.事实上它确实没有声明,因为 MinGW 的 <netfw.h> 没有声明 NetFwRule。 MSVC however does.然而,MSVC 确实如此。

Your GCC was too old.你的 GCC 太旧了。

You can get a newer version via MSYS' pacman, or download a standalone build, for example from http://winlibs.com/ which will work just as well if you don't need MSYS2.您可以通过 MSYS 的 pacman 获得更新版本,或下载独立版本,例如从http://winlibs.com/下载,如果您不需要 MSYS2,它也可以正常工作。

Okay, I have tried to use MinGW 64 bit just as IInspectable suggested, but that does not work either - the netfw.h header still does not provide NetFwRule.好的,我尝试按照 IInspectable 的建议使用 MinGW 64 位,但这也不起作用 - netfw.h header 仍然不提供 NetFwRule。 However i have installed g++ along with MSYS2 (the version that rustyx is using), which just works as expected.但是我已经安装了 g++ 和 MSYS2(rustyx 正在使用的版本),它按预期工作。 So if anyone faces the same issue I would suggest to use MinGW along with MSYS2 and not standalone.因此,如果有人遇到同样的问题,我建议将 MinGW 与 MSYS2 一起使用,而不是独立使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM