Click to See Complete Forum and Search --> : Cryptography in VC++ 6


kempyeng
March 25th, 2004, 11:08 PM
Hi all,
I try to make simple program (from msdn sample) to encrypt data using Visual C++ 6, this is the program :

#include // CryptoAPI definitions

#define MS_DEF_PROV "Microsoft Base Cryptographic Provider v1.0"
#define PROV_RSA_FULL 1

BOOL bResult;
HCRYPTPROC hProv;

// Attempt to acquire a handle to the default key container.
bResult = CryptAcquireContext(
&hProv, // Variable to hold returned handle.
NULL, // Use default key container.
MS_DEF_PROV, // Use default CSP.
PROV_RSA_FULL, // Type of provider to acquire.
0); // No special action.

// Release handle to container.
CryptReleaseContext(hProv);

but when I compile those codes, I get error messages like this :

error C2065: 'HCRYPTPROC' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'hProv'
error C2065: 'hProv' : undeclared identifier
error C2065: 'CryptAcquireContext' : undeclared identifier
error C2065: 'CryptReleaseContext' : undeclared identifier

I don't understand, these codes are very simple and I capture these codes from MSDN (so it must be success). Can anyone help me ?
Thanks

simpleman
March 26th, 2004, 01:39 AM
Hi

I am simpleman

i think you should change the code like this...

#include <wincrypt.h> // CryptoAPI definitions
/*
For non-C/C++ users the constants used here are:
#define MS_DEF_PROV "Microsoft Base Cryptographic Provider v1.0"
#define PROV_RSA_FULL 1
*/

BOOL bResult;
HCRYPTPROV hProv;

// Attempt to acquire a handle to the default key container.
bResult = CryptAcquireContext(
&hProv, // Variable to hold returned handle.
NULL, // Use default key container.
MS_DEF_PROV, // Use default CSP.
PROV_RSA_FULL, // Type of provider to acquire.
0); // No special action.
.
.
.
//Do some work.
.
.
.
// Release handle to container.
CryptReleaseContext(hProv, 0);



i just changed from HCRYPTPROC to HCRYPTPROV and added zero into the CryptReleaseContext(hProv, 0);

Good luck to you ^^

kempyeng
March 28th, 2004, 08:54 PM
Yes, it work now
And I have to add this code

#define _WIN32_WINNT 0x0400

before #include<wincrypt.h>

Thanks