title: GetAdaptersInfo not working on Delphi XE6
body: <p>I finally bit the bullet and bought XE6 and as expected, the Unicode conversion is turning into a bit of a nightmare. So if anyone can enlighten me on why this simple Windows API call fails, it would be most appreciated. The function does not return an error, the first call gets the correct buffer length, the second call fills the record with garbage.</p>
  
  <p>This works fine under Delphi 2007 but fails on XE6 with unicode garbage in the pAdapterinfo return record even though it is explicitly declared with AnsiString in IpTypes.pas</p>
  
  <p>System is Win7(64) but compiling for 32 bits.</p>
  
  <pre><code>uses iphlpapi, IpTypes;
  
  function GetFirstAdapterMacAddress:AnsiString;
  var pAdapterInfo:PIP_ADAPTER_INFO;
      BufLen,Status:cardinal; i:Integer;
  begin
    result:='';
    BufLen:= sizeof(IP_ADAPTER_INFO);
    GetAdaptersInfo(nil, BufLen);
    pAdapterInfo:= AllocMem(BufLen);
    try
      Status:= GetAdaptersInfo(pAdapterInfo,BufLen);
      if (Status &lt;&gt; ERROR_SUCCESS) then
      begin
        case Status of
          ERROR_NOT_SUPPORTED: raise exception.create('GetAdaptersInfo is not supported by the operating ' +
                                       'system running on the local computer.');
          ERROR_NO_DATA: raise exception.create('No network adapter on the local computer.');
        else
          raiselastOSerror;
        end;
        Exit;
      end;
      while (pAdapterInfo^.AddressLength=0) and (pAdapterInfo^.next&lt;&gt;nil) do
       pAdapterInfo:=pAdapterInfo.next;
      if pAdapterInfo^.AddressLength&gt;0 then
      for i := 0 to pAdapterInfo^.AddressLength - 1 do
        result := result + IntToHex(pAdapterInfo^.Address[I], 2);
    finally
      Freemem(pAdapterInfo);
    end;
  end;
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>I did some more checking. I created a new simple application with one form and a button and called the routine when the button was pressed and it worked.</p>
  
  <p>The differences are...in the working form the size of IP_ADAPTER_INFO is 640 bytes.</p>
  
  <p>When this routine is used in a more complex application it fails and the size of IP_ADAPTER_INFO displays as 1192 bytes.</p>
  
  <p>At this point, it seems the complier is unilaterally deciding to change the type of the ansi chars in the structures to unicode chars. The debugger is showing AdapterName and description fields in unicode form. I did a grep of the system source code, there are no other versions of this data type declared in the library code apart from in the Indy library and that is just a duplicate.</p>
  
  <p>Here is the data structure definition in IPtypes</p>
  
  <pre><code>  PIP_ADAPTER_INFO = ^IP_ADAPTER_INFO;
    {$EXTERNALSYM PIP_ADAPTER_INFO}
    _IP_ADAPTER_INFO = record
      Next: PIP_ADAPTER_INFO;
      ComboIndex: DWORD;
      AdapterName: array [0..MAX_ADAPTER_NAME_LENGTH + 3] of AnsiChar;
      Description: array [0..MAX_ADAPTER_DESCRIPTION_LENGTH + 3] of AnsiChar;
      AddressLength: UINT;
      Address: array [0..MAX_ADAPTER_ADDRESS_LENGTH - 1] of BYTE;
      Index: DWORD;
      Type_: UINT;
      DhcpEnabled: UINT;
      CurrentIpAddress: PIP_ADDR_STRING;
      IpAddressList: IP_ADDR_STRING;
      GatewayList: IP_ADDR_STRING;
      DhcpServer: IP_ADDR_STRING;
      HaveWins: BOOL;
      PrimaryWinsServer: IP_ADDR_STRING;
      SecondaryWinsServer: IP_ADDR_STRING;
      LeaseObtained: time_t;
      LeaseExpires: time_t;
    end;
  </code></pre>
  
  <p>Looks like a compiler bug.</p>