Search code examples
c++windowsvisual-studio-2015mib

How to compile a code with MIB_IPINTERFACE_ROW structure


I am trying to compiling a code with the MIB_IPINTERFACE_ROW structure. Let's include the following class in my working code:

class IpInterfaceRow {
private:
    MIB_IPINTERFACE_ROW mib_ipinterface_row;
};

Using Visual Studio 2015 I am facing the following errors: unknown override specifier (C3646) and missing type specifier - int assumed. Note: C++ does not support default-int (C4430)

That you can check here - C3646 and here - C4430. Really the second one is more a warning, that I could turn off with #pragma warning, and I think it depends on the first one (since the compiler does not recognize MIB_IPINTERFACE_ROW, it tries to give it the value of an int, hence the second error) then, I am focusing on the first one.

I think that maybe is a problem of headers that I include/not include in the wrong order? I tried a lot of options: #include <netioapi.h>, #include <iphlapi.h> and much more... For example, from here, I tried to use

#include <ws2def.h>
#include <ws2ipdef.h>
#include <iphlpapi.h>

but same result...I have the same problem if I try to use MIB_INTERFACE_TABLE. I also tried to compile the example code in GetIpInterfaceTable(), which has this includes

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <windows.h>
#include <winsock2.h>
#include <ws2ipdef.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>

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

but again the same result...

Someone has an idea of what can be wrong? what does error C3646 could mean in my case?


Solution

  • The following includes indeed work

    #include <winsock2.h>
    #include <windows.h>
    #include <ws2ipdef.h>
    #include <iphlpapi.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    #pragma comment(lib, "iphlpapi.lib")
    

    In my code there were two files included before that gave me the problem:

    • The first included iphlpapi.h (then, included before ws2ipdef.h)

    • The second included netcfgx.h that includes windows.h (then included before winsock2.h)

    In particular note that other headers i.e. in my case netcfgx.h can include some of the headers, i.e. windows.h and make the order wrong