MSDN RegQueryValueEx API return code 2 RRS feed

  • Question

  • In the following code, the RegQueryValueEx() ret (returned code) is 2 indicated the failure (no matter how I changed "IPAddress" or "\\IPaddress"...etc. on both win32 or win64 vs2013) 

    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces"), 0, KEY_QUERY_VALUE, &hActiveKey) == ERROR_SUCCESS)
    int ret = RegQueryValueEx(hActiveKey, TEXT("IPAddress"), NULL, NULL, (BYTE *)ipaddr, &dwBufSize);
    if (ret != ERROR_SUCCESS)
    printf("RegQueryValueEx ErrCode %d\n", ret);


    My intention is to get and set the static IP address.

    Any help is highly appreciated.

    Monday, January 25, 2016 11:28 PM