title: Difference between calling 64-bit API function in Debug and Release mode
body: <p>I have a problem converting a 32-bit to 64-bit code using the <a href="http://www.koders.com/delphi/fid06860D8F8B7701BD0B42D42112F4A47B08DCA76D.aspx?s=proxy#L177" rel="nofollow"><code>lsaapi.pas unit</code></a> 
  with a small Unicode <code>PChar</code> to <code>PAnsiChar</code> correction.</p>
  
  <p>The following code will work in 32-bit mode but not in 64-bit.
  Running the procedure (not in 64-bit Debug mode!), getting the error message 
  <code>invalid parameter</code> by calling <code>LsaQueryInformationPolicy()</code></p>
  
  <p>Any ideas, what's wrong ?<br>
  Why is there a different behavior running this code in the 64-bit debug and non-debug mode ?<br>
  Maybe a record alignment problem in 64-bit ?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>uses
    lsaapi;
  
  function GetDomainName: string;
  var
    Buffer: Pointer;
    Status: NTStatus;
    PolicyHandle: LSA_HANDLE;
    ComputerName: TLsaUnicodeStr;
    Attributes: TLsaObjectAttributes;
    PolicyAccountDomainInfo: PPolicyAccountDomainInfo;
  begin
    ComputerName := TLsaUnicodeStr.CreateFromStr('');
    try
      FillChar(Attributes, SizeOf(Attributes), 0);    
      Status := LsaOpenPolicy(ComputerName.Value, Attributes, 
        POLICY_VIEW_LOCAL_INFORMATION, PolicyHandle);
      if Status &lt;&gt; STATUS_SUCCESS then
        raise Exception.Create('LsaOpenPolicy Failed: ' + 
          SysErrorMessage(LsaNtStatusToWinError(Status)));    
      try
        Status := LsaQueryInformationPolicy(PolicyHandle, 
          PolicyPrimaryDomainInformation, Buffer);
        if Status &lt;&gt; STATUS_SUCCESS then
          raise Exception.Create('LsaQueryInformationPolicy Failed: ' +
            SysErrorMessage(LsaNtStatusToWinError(Status)));    
        try
          PolicyAccountDomainInfo := Buffer;
          Result := PolicyAccountDomainInfo.DomainName.Buffer;
        finally
          LsaFreeMemory(Buffer)
        end;
      finally
        LsaClose(PolicyHandle)
      end;
    finally
      ComputerName.Free;
    end;
  end;
  </code></pre>