'HCRYPTHASH' : undeclared identifier 类似错误的解决办法

在编译一个cpp程序时,明明已经 include <wincrypt.h>,可还是报错

D:\crypt\crypt.cpp(20) : error C2065: 'HCRYPTHASH' : undeclared identifier
D:\crypt\crypt.cpp(20) : error C2146: syntax error : missing ';' before identifier 'hHash'
D:\crypt\crypt.cpp(20) : error C2065: 'hHash' : undeclared identifier
D:\crypt\crypt.cpp(22) : error C2065: 'HCRYPTKEY' : undeclared identifier
D:\crypt\crypt.cpp(22) : error C2146: syntax error : missing ';' before identifier 'hKey'
D:\crypt\crypt.cpp(22) : error C2065: 'hKey' : undeclared identifier
D:\crypt\crypt.cpp(24) : error C2065: 'HCRYPTPROV' : undeclared identifier
D:\crypt\crypt.cpp(24) : error C2146: syntax error : missing ';' before identifier 'hProv'
D:\crypt\crypt.cpp(24) : error C2065: 'hProv' : undeclared identifier
D:\crypt\crypt.cpp(32) : error C2065: 'CryptAcquireContext' : undeclared identifier
D:\crypt\crypt.cpp(38) : error C2065: 'CryptCreateHash' : undeclared identifier
D:\crypt\crypt.cpp(54) : error C2065: 'CryptHashData' : undeclared identifier
D:\crypt\crypt.cpp(70) : error C2065: 'CryptDeriveKey' : undeclared identifier
D:\crypt\crypt.cpp(105) : error C2065: 'CryptEncrypt' : undeclared identifier
D:\crypt\crypt.cpp(151) : error C2065: 'CryptDestroyHash' : undeclared identifier
D:\crypt\crypt.cpp(157) : error C2065: 'CryptDestroyKey' : undeclared identifier

原因是:

vc6缺省是不定义_WIN32_WINNT宏的。 
而在wincrypt.h中有 
#if (_WIN32_WINNT >= 0x0400) 
... 
#endif

解决办法是:
在stdafx.h中添加

#ifndef   _WIN32_WINNT 
#define   _WIN32_WINNT   0x0400 
#endif

你可能感兴趣的:(hash)