0

I'm using Visual Studios 2012 on Windows 8.1, on a 64 bit machine. I'm having trouble compiling the following code for c++, getting the above error:

#include <windows.h>
#include <wincrypt.h>
void MD5Init(MD5Context *ctx)
{
    CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &ctx->hHash);
}

However, this seems to be the way this is called (here is one which has the same call and gives me the same error). VS suggests a couple of possible fixes, which I'll try, but does anyone know why this behaviour is happening and how to avoid it?

The suggested fixes are:

error C2664: 'CryptCreateHash' : cannot convert parameter 5 from 'unsigned long *' to 'HCRYPTHASH *' Types pointed to are unrelated;

conversion requires reinterpret_cast, C-style cast or function-style cast

Thanks,

Aodhán

Edit: It doesn't happen for 32 bit compilation, so I guess that's what the examples I've read were done in. I'll update whether the suggested fixes worked for 64 bit compilation.

AodhanOL
  • 630
  • 7
  • 26
  • 1
    _conversion requires reinterpret_cast, C-style cast or function-style cast_ Doesn't this help you? – aslg Jun 16 '15 at 10:47
  • Yes, I'm going to try out those and see if they work - but none of the examples I've seen used those so I'm asking the question why it should be the case that it happens here. – AodhanOL Jun 16 '15 at 10:59
  • Your MD5Context.hHash member isn't big enough in 64-bit mode. The simple workaround is to declare it as HCRYPTHASH instead of unsigned long. – Hans Passant Jun 16 '15 at 11:19
  • Thank you, I'm glad I know that now. – AodhanOL Jun 16 '15 at 11:22

0 Answers0