Partager via


Obtaining the Buffer Size

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

Many of the IP Helper functions work similarly. To retrieve the table of data which you are requesting, you need to know how large a buffer to pass. So the function is first called with a null buffer and a pointer to a location for the required buffer size. The function is then called with the appropriate buffer size. This is shown in the code snippet below.

// Get the Network Parameters
//Note that this code snippet can also be used 
//for other 'get' functions, such as GetTcpStatistics, 
//GetIpAddrTable, and so on.
PFIXED_INFO pNetworkParams = NULL;
ULONG uSizeNetworkParams = 0;
DWORD status;

// Find out how large the buffer needs to be to hold the data
status = GetNetworkParams(pNetworkParams, &uSizeNetworkParams);
if (status == ERROR_BUFFER_OVERFLOW) {
   // Allocate a buffer of the appropriate size
   if (!(pNetworkParams = (PFIXED_INFO) malloc(uSizeNetworkParams))) {
      return(1);
   }
   // Obtain Adapter Info
   status = GetNetworkParams(pNetworkParams, &uSizeNetworkParams);
}

See Also

Concepts

IP Helper Code Samples