0

我正在尝试使用crypto++编译一个项目。我的项目正在使用 clr ,当我尝试编译代码时,最终出现以下错误:

'main' : this function cannot be compiled as managed, consider using #pragma unmanaged

'int main(cli::array<Type> ^)' : managed type or function cannot be used in an unmanaged function

我的项目正在使用clr,我正在/MD用作运行时库。我在编译crypto++时设置了相同的参数。

编辑:我的主要功能

     int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");

    // Generate keys
    AutoSeededRandomPool rng;

    InvertibleRSAFunction params;
    params.GenerateRandomWithKeySize( rng, 1536 );

    RSA::PrivateKey privateKey( params );
    RSA::PublicKey publicKey( params );

    std::string plain="RSA Encryption", cipher, recovered;


    // Encryption
    RSAES_OAEP_SHA_Encryptor e( publicKey );

    StringSource( plain, true,
        new PK_EncryptorFilter( rng, e,
            new StringSink( cipher )
        ) // PK_EncryptorFilter
     ); // StringSource

    // Decryption
    RSAES_OAEP_SHA_Decryptor d( privateKey );

    StringSource( cipher, true,
        new PK_DecryptorFilter( rng, d,
            new StringSink( recovered )
        ) // PK_DecryptorFilter
     ); // StringSource

    assert( plain == recovered );
    std::cin.ignore();
    return 0;
}
4

1 回答 1

2

如果您尝试在托管代码中执行任何非托管指令,您将收到此错误。见这里

assert()和之std::string类的分别是本地方法/类型,这意味着它们处理原始指针并且不遵守托管 C++ 的规则。通过使用PInvoke/DllImport可以实现将此类非托管代码与托管代码混合。

于 2012-11-06T11:15:37.897 回答