CRYTOAPI 库调用出错

调试中,出现以下错误:

Compiling...
Keycos.cpp
d:/soft work/other/devinterface/keycos.cpp(34) : warning C4101: 'ifData' : unreferenced local variable
d:/soft work/other/devinterface/keycos.cpp(383) : error C2065: 'HCRYPTPROV' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(383) : error C2146: syntax error : missing ';' before identifier 'hProv'
d:/soft work/other/devinterface/keycos.cpp(383) : error C2065: 'hProv' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(384) : error C2065: 'HCRYPTKEY' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(384) : error C2146: syntax error : missing ';' before identifier 'hKey'
d:/soft work/other/devinterface/keycos.cpp(384) : error C2065: 'hKey' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(392) : error C2065: 'HCERTSTORE' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(392) : error C2146: syntax error : missing ';' before identifier 'hSysStore'
d:/soft work/other/devinterface/keycos.cpp(392) : error C2065: 'hSysStore' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(393) : error C2065: 'PCCERT_CONTEXT' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(393) : error C2146: syntax error : missing ';' before identifier 'pCertContext'
d:/soft work/other/devinterface/keycos.cpp(393) : error C2065: 'pCertContext' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(394) : error C2065: 'CERT_CONTEXT' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(394) : error C2146: syntax error : missing ';' before identifier 'MyContext'
d:/soft work/other/devinterface/keycos.cpp(394) : error C2065: 'MyContext' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(404) : error C2065: 'CryptAcquireContext' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(404) : error C2065: 'sContainer' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(404) : error C2065: 'sCspName' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(404) : error C2065: 'PROV_RSA_FULL' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(407) : error C2065: 'CryptGenKey' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(409) : error C2065: 'AT_KEYEXCHANGE' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(410) : error C2065: 'CRYPT_EXPORTABLE' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(416) : error C2065: 'CryptGetKeyParam' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(418) : error C2065: 'KP_CERTIFICATE' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(435) : error C2065: 'CertOpenSystemStore' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(435) : error C2065: 'sNewItStoreName' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(438) : error C2228: left of '.cbCertEncoded' must have class/struct/union type
d:/soft work/other/devinterface/keycos.cpp(439) : error C2228: left of '.dwCertEncodingType' must have class/struct/union type
d:/soft work/other/devinterface/keycos.cpp(439) : error C2065: 'X509_ASN_ENCODING' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(440) : error C2228: left of '.hCertStore' must have class/struct/union type
d:/soft work/other/devinterface/keycos.cpp(441) : error C2228: left of '.pbCertEncoded' must have class/struct/union type
d:/soft work/other/devinterface/keycos.cpp(443) : error C2440: '=' : cannot convert from 'int *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
d:/soft work/other/devinterface/keycos.cpp(445) : error C2065: 'PCERT_CONTEXT' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(445) : error C2146: syntax error : missing ';' before identifier 'CertCreateCertificateContext'
d:/soft work/other/devinterface/keycos.cpp(445) : error C2065: 'CertCreateCertificateContext' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(446) : error C2065: 'PKCS_7_ASN_ENCODING' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(456) : error C2065: 'CertAddCertificateContextToStore' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(458) : error C2065: 'CERT_STORE_ADD_ALWAYS' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(466) : error C2227: left of '->pCertInfo' must point to class/struct/union
d:/soft work/other/devinterface/keycos.cpp(466) : error C2227: left of '->SerialNumber' must point to class/struct/union
d:/soft work/other/devinterface/keycos.cpp(466) : error C2228: left of '.pbData' must have class/struct/union type
d:/soft work/other/devinterface/keycos.cpp(466) : error C2227: left of '->pCertInfo' must point to class/struct/union
d:/soft work/other/devinterface/keycos.cpp(466) : error C2227: left of '->SerialNumber' must point to class/struct/union
d:/soft work/other/devinterface/keycos.cpp(466) : error C2228: left of '.cbData' must have class/struct/union type
d:/soft work/other/devinterface/keycos.cpp(468) : error C2065: 'CertFreeCertificateContext' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(469) : error C2065: 'CertCloseStore' : undeclared identifier
d:/soft work/other/devinterface/keycos.cpp(472) : error C2065: 'CERT_CLOSE_STORE_FORCE_FLAG' : undeclared identifier
KeyMethd.cpp
Error executing cl.exe.

DevInterface.dll - 47 error(s), 1 warning(s)

 

已经添加如下条件:

#include <hlguids.h>
#include <stdio.h>

#include <setupapi.h>
#pragma  comment(lib,"setupapi.lib")

#include  <WINCRYPT.h>
#pragma comment(lib,"CRYPT32.lib")

 

但是错误依然.........................

 

解决方案:

1. VC 6.0 所带的CRYTOAPI 比较陈旧,需要重新下载并替换之,可以去微软下载,我没有式过

2. 用比VC 6.0 更高的编译环境编译,我用的是 VS 2008,通过。

你可能感兴趣的:(CRYTOAPI 库调用出错)