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.
<
Your code needs to look something like this:
// First get the desired size.
unsigned long outBufLen = 0;
DWORD dwResult = GetAdaptersInfo(NULL, &outBufLen);
if (dwResult == ERROR_BUFFER_OVERFLOW) // This is what we're expecting
{
// Now allocate a structure of the requried size.
PIP_ADAPTER_INFO pIpAdapterInfo = (PIP_ADAPTER_INFO) malloc(outBufLen);
dwResult = GetAdaptersInfo(pIpAdapterInfo, &outBufLen);
if (dwResult == ERROR_SUCCESS)
{
// Yay!
Edit: See also Jeremy Friesner's answer for why this code isn't quite enough.