title: CryptAcquireContext and CryptDeriveKey x64 mode
body: <p>Delphi Xe4. Test on Win7Pro x64, Win8Ent x64, WinSrv2012;</p>
  
  <pre><code>Const
  
  CGuAdvapi32dll=WinApi.Windows.Advapi32;
  
  CALG_MD2      = 32769;
  CALG_MD4      = 32770;
  CALG_MD5      = 32771;
  CALG_SHA      = 32772;
  CALG_SHA_1    = 32772; // CALG_SHA
  CALG_SHA_256  = 32780;
  CALG_SHA_384  = 32781;
  CALG_SHA_512  = 32782;
  
  CALG_DES      = 26113;
  CALG_RC2      = 26114;
  CALG_3DES     = 26115;
  CALG_3DES_112 = 26121;
  CALG_AES_128  = 26126;
  CALG_AES_192  = 26127;
  CALG_AES_256  = 26128;
  CALG_AES      = 26128; // CALG_AES_256
  CALG_RC4      = 26625;
  
  PROV_RSA_AES = 24;        // The PROV_SSL provider type supports US AES crypto-algorithm
  CRYPT_VERIFYCONTEXT = $F0000000;
  
  
  {S} Function GuCryptAcquireContext(hProv: PULong; Container: LPCTSTR; Provider: LPCTSTR; ProvType: DWord; Flags: DWord): Bool; StdCall; External CGuAdvapi32dll Name 'CryptAcquireContextW';
  {S} Function GuCryptReleaseContext(hProv: ULong; Flags: DWord): Bool; StdCall; External CGuAdvapi32dll Name 'CryptReleaseContext';
  {S} Function GuCryptCreateHash(hProv: ULong; AlgId: ULong; hKey: ULong; Flags: DWord; Hash: PULong): Bool; StdCall; External CGuAdvapi32dll Name 'CryptCreateHash';
  {S} Function GuCryptHashData(hHash: ULong; Data: PByte; DataLen: DWord; Flags: DWord): Bool; StdCall; External CGuAdvapi32dll Name 'CryptHashData';
  {S} Function GuCryptDeriveKey(hProv: ULong; AlgId: ULong; hData: ULong; Flags: DWord; Key: PULong): Bool; StdCall; External CGuAdvapi32dll Name 'CryptDeriveKey';
  {S} Function GuCryptDestroyHash(hHash: ULong): Bool; StdCall; External CGuAdvapi32dll Name 'CryptDestroyHash';
  {S} Function GuCryptDestroyKey(hKey: ULong): Bool; StdCall; External CGuAdvapi32dll Name 'CryptDestroyKey';
  </code></pre>
  
  <p>...</p>
  
  <pre><code>Procedure Test64;
  var   hProv, hKey, hHash: Ulong; key:string; CGuSoC:dword;
  begin
    key:='my test password';CGuSoC:=sizeof(char);
    if not GuCryptAcquireContext(@hProv, nil, nil, PROV_RSA_AES, CRYPT_VERIFYCONTEXT) then MessageBox(0, 'Not CAC', 0, 0);
     MessageBox(0, PChar(IntToStr(hprov)), 0, 0); // &lt; --- 1 check !
    if not GuCryptCreateHash(hProv, CALG_MD2{MD5, SHA}, 0, 0, @hHash) then MessageBox(0, 'Not CCH', 0, 0);
    if not GuCryptHashData(hHash, @key[1], Length(key)*CGuSoC, 0) then MessageBox(0, 'Not CHD', 0, 0);
    if not GuCryptDeriveKey(hProv, CALG_RC4{RC2, AES}, hHash, 0, @hKey) then MessageBox(0, 'Not CDK', 0, 0);
    if not GuCryptDestroyHash(hHash) then MessageBox(0, 'Not CDH', 0, 0);
     MessageBox(0, PChar(IntToStr(hprov)), 0, 0); // &lt; --- 2 check !
    if not GuCryptDestroyKey(hKey) then MessageBox(0, 'Not CDK', 0, 0);
    if hProv=0 then MessageBox(0, 'hProv=0!', 0, 0) else if not GuCryptReleaseContext(hProv, 0) then MessageBox(0, 'Not CRC', 0, 0);
  end;
  </code></pre>
  
  <p>Q: Compile with target platforms "32-bit windows", all Ok. In check string 1 and 2 show big numeric ID, ex. 882345.</p>
  
  <p>Compile with target platforms "64-bit windows", working ok, but show "0" in check 2 (check 1 = ok, big num). <strong>Why?</strong></p>
  
  <p>p.s. I change hProv variable type to ULong64 (in proc.Test64 var. and GuCryptAcquireContext define), but no result.</p>
  
  <p>Sorry for the bad English.</p>