GetAdaptersInfo and GetAdaptersAddressess BufferLength Param

前端 未结 3 1157
误落风尘
误落风尘 2021-01-07 07:18

I\'ve got some legacy code in C++ here that does some things I don\'t understand. I\'m running it in Visual C++ 2008 Express Edition on a machine running Windows XP.

<
3条回答
  •  半阙折子戏
    2021-01-07 08:06

    Indeed, Using Visual studio 6, I used to get the number of adapters by:

    DWORD drc = GetAdaptersInfo(NULL, &(Buflen = 0L));
    
    if (drc == ERROR_BUFFER_OVERFLOW)
      n = Buflen / sizeof(IP_ADAPTER_INFO);
    

    It was all right, for instance for 2 adapters Buflen was set to 1280 and sizeof(IP_ADAPTER_INFO) was 640.

    Now I am using Visual C++ 2008 Express and my result is truncated because the function still sets Buflen to 1280 but the value of sizeof(IP_ADAPTER_INFO) is now 648!

    Is this a bug or am I missing something?

提交回复
热议问题