c++winapiencryptioncrypto++cbc-mode

'byte' : ambiguous symbol error when using of Crypto++ and Windows SDK


In Visual Studio 2012, I'm trying to encrypt a file with Crypto++ library with AES encryption and CBC mode as following :

#include <Windows.h>
#include "aes.h"
#include "modes.h"
#include "files.h"
#include <Shlwapi.h>

using namespace CryptoPP;

INT main(INT argc, CHAR *argv[])
{
    CHAR szKey[16] = {0};
    CHAR szInitVector[AES::DEFAULT_KEYLENGTH] = {0};

    StrCpyA(szKey, "qqwweeff88lliioo");
    StrCpyA(szInitVector, "eerrttooppkkllhh");

    CBC_Mode<AES>::Encryption encryptor((byte*)szKey, AES::DEFAULT_KEYLENGTH, (byte*)szInitVector);
    FileSource fs("in.txt", true, new StreamTransformationFilter(encryptor, new FileSink("out.aes")));

    return 0;
}

In Qt it does work!, But here I wondered why got the following error :

error C2872: 'byte' : ambiguous symbol
could be 'c:\program files (x86)\windows kits\8.0\include\shared\rpcndr.h(164) : unsigned char byte'
or 'z:\cryptography\app_aesencryption\aes headers\config.h(237) : CryptoPP::byte'

Due to prevent of ambiguous symbol error, even I cast bellow statement with CryptoPP::byte* :

CBC_Mode<AES>::Encryption encryptor((CryptoPP::byte*)szKey, AES::DEFAULT_KEYLENGTH, (CryptoPP::byte*)szInitVector);

I didn't get any error for 'byte' : ambiguous symbol, But It give me many errors as :

error LNK 2038

By the way, I linked .lib file of Crypto++, So I think this error is Unlikely for this. Is last error related to CryptoPP::byte*? Is there any solution?


Solution

  • The first problem solved with changing byte* to CryptoPP::byte* :

    CBC_Mode<AES>::Encryption encryptor((CryptoPP::byte*)szKey, AES::DEFAULT_KEYLENGTH, (CryptoPP::byte*)szInitVector);
    

    But to solving the second problem (error LNK 2038) :

    This is related to link error, Every body that using of crypto++ in Visual Studio may have this problem.

    First I was download library from bellow link for visual studio in which containt .sln (VS Solution) :

    But I forgot something in project properties :

    Finally, I set Runtime Library option to Multi-threaded Debug (/MTd)

    This option is in :