简体   繁体   中英

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. I am following this example using the MingW g++ compiler . 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. 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. However it is absolutely neccessary for the project to use the MinGW g++ compiler.

This particular code snippet as shown in the example link won't work, since NetFwRule is not defined:

// 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?

FYI: I have MinGW 32 bit with posix thread for the i686 architecture installed.

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

The error message is: 'NetFwRule' was not declared in this scope

In fact it really is not declared, since the <netfw.h> of MinGW does not declare NetFwRule. MSVC however does.

Your GCC was too old.

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.

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. However i have installed g++ along with MSYS2 (the version that rustyx is using), which just works as expected. So if anyone faces the same issue I would suggest to use MinGW along with MSYS2 and not standalone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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