locked
How to call method EnableStatic() in C++ ? RRS feed

  • Question

  • Hello!

    Like in the title.

    I'm a quite inexperienced ;-; and I have hard time with calling the function EnableStatic() from Win32_NetworkAdapterConfiguration class in C++. So how to do it?

    I would really appreciate an example or simple program with it!

    --------

    Additional Info:

    • I've tried use this part of calling code:
    UINT ipaddr = inet_addr("155.34.22.0");
    UINT subnet = inet_addr("255.255.255.0");

    Win32_NetworkAdapterConfiguration Adapter;
    Adapter.EnableStatic(ipaddr,subnet);

    • The method's website:

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa390383(v=vs.85).aspx



    • Edited by CubaQ Tuesday, March 15, 2016 10:57 AM
    Monday, March 14, 2016 3:59 PM

Answers

  • Win32_NetworkAdapterConfiguration is not an API in the sense you are used to.  It is a WMI method.  It IS possible to make WMI calls from C++, but it is quite tedious.  You have to get an IWbemServices COM object, create an instance of the class, and call the method of the class, all indirectly.  There is an example here:

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa390421(v=vs.85).aspx

    WMI is easier to handle from C#.  But, to be brutally honest, it is usually easier to manipulate network adapters by constructing a "netsh" command line as a string and calling it using "system" or CreateProcess.  Here's some netsh commands:

    https://www.petri.com/configure_tcp_ip_from_cmd


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    • Proposed as answer by Baron Bi Tuesday, March 15, 2016 2:45 AM
    • Marked as answer by CubaQ Tuesday, March 15, 2016 2:12 PM
    Monday, March 14, 2016 4:22 PM
  • You're dealing with WMI class methods, not C++ methods.

    This example shows how to call the Create method of WMI's Win32_Process class.


    • Marked as answer by CubaQ Tuesday, March 15, 2016 2:12 PM
    Monday, March 14, 2016 5:07 PM

All replies

  • Win32_NetworkAdapterConfiguration is not an API in the sense you are used to.  It is a WMI method.  It IS possible to make WMI calls from C++, but it is quite tedious.  You have to get an IWbemServices COM object, create an instance of the class, and call the method of the class, all indirectly.  There is an example here:

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa390421(v=vs.85).aspx

    WMI is easier to handle from C#.  But, to be brutally honest, it is usually easier to manipulate network adapters by constructing a "netsh" command line as a string and calling it using "system" or CreateProcess.  Here's some netsh commands:

    https://www.petri.com/configure_tcp_ip_from_cmd


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    • Proposed as answer by Baron Bi Tuesday, March 15, 2016 2:45 AM
    • Marked as answer by CubaQ Tuesday, March 15, 2016 2:12 PM
    Monday, March 14, 2016 4:22 PM
  • You're dealing with WMI class methods, not C++ methods.

    This example shows how to call the Create method of WMI's Win32_Process class.


    • Marked as answer by CubaQ Tuesday, March 15, 2016 2:12 PM
    Monday, March 14, 2016 5:07 PM