Hi CryptoPP and Wei Dai,

To follow up my old post about Crypto++ and Managed C++,
recently I could figure out how to use Crypto++ under Managed C++
with VC++ 7.1 and /clr compiler switch for .NET, using Crypto++ 5.2 in
source form.

The updated sample code to show some random number is:

-------------------------------------------------------
#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

#pragma unmanaged

#include "osrng.h"
#include "des.h"

using namespace CryptoPP;

#pragma managed

int main()
{
        AutoSeededX917RNG<DES_EDE3> rng;
        int i = rng.GenerateWord32();
        Console::WriteLine("{0:d}", __box(i));

        return 0;
}

-------------------------------------------------------

This compiles, links, runs fine.
Though I put "#pragma unmanaged" before header inclusion, it's not
enough or doesn't mean much, I had to add it in pch.h (which is nice
architecture of Crypto++ to insert prologue) of Crypto++.
Another failure of me in the previous try is that I wrote _tmain for the
entry point.

Anyway I hope it helps someone. Not sure what Wei thinks about
Managed C++, but patching pch.h or somewhere else to allow
Crypto++ used from Managed C++ is cool, I think.


Ken

On Wed, 21 Apr 2004 06:48:31 +0900
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> On Tue, 20 Apr 2004 10:26:19 -0400
> "Walton, Jeffrey" <[EMAIL PROTECTED]> wrote:
> > I can't speak of managed code, but I have read about some issues with the
> > compiler. Google may prove useful.
> > 
> > I've also found if I stuff things in afx, I'll get the error every now and
> > again (being lazy and using it as a common header).
> 
> In the stdafx.h of my sample code, it only contains tchar.h, and nothing else
> (in default it contains iostream, but I removed it), so afx thing has nothing
> with it.
> 
> I could compile & link the sample code without /clr, so this is
> Managed C++ specific problem in Crypto++. I haven't built the Crypto++ library,
> but rather added necessary source files of Crypto++ into the samle project.
> 
> In my understanding of MC++, if you don't touch Managed types, you can
> use template and things without a problem. Is it correct? I could use other
> template-intensive Unmanaged C++ library with /clr.
> 
> Ken
> 
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED]
> > > [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
> > > Sent: Monday, April 19, 2004 9:59 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: CryptoPP and Managed C++
> > >
> > >
> > > Hello everyone and Wei,
> > >
> > > I compiled the following code under VC++ 7.1 with /clr switch
> > > to make it recognized as Managed C++ code. My Crypto++
> > > version is the latest off CVS c5 branch.
> > >
> > > -----------------------------------------------------------
> > > #include "stdafx.h"
> > >
> > > #using <mscorlib.dll>
> > >
> > > using namespace System;
> > >
> > > #include "osrng.h"
> > > #include "des.h"
> > >
> > > using namespace CryptoPP;
> > >
> > > int _tmain()
> > > {
> > >   AutoSeededX917RNG<DES_EDE3> rng;
> > >
> > >   return 0;
> > > }
> > >
> > > ------------------------------------------------------------
> > >
> > > While compilation is OK except for a warning at integer.cpp(1567)
> > > "warning C4561: '__fastcall' incompatible with the '/clr'
> > > option", I had linker errors in CryptoPP::CheckedSetKey:
> > >
> > > test error LNK2005: "void __cdecl
> > > CryptoPP::CheckedSetKey<class
> > > CryptoPP::BlockCipherFinal<0,class CryptoPP::DES::Base>
> > > >(class CryptoPP::BlockCipherFinal<0,class
> > > CryptoPP::DES::Base> *,enum CryptoPP::CipherDir,unsigned char
> > > const *,unsigned int,class CryptoPP::NameValuePairs const &)"
> > > ([EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@@
> > > @CryptoPP@@@CryptoPP@@[EMAIL PROTECTED]@[EMAIL PROTECTED]
> > > [EMAIL PROTECTED]@@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@0@@Z)
> > > already defined in test.obj test error LNK2005: "void __cdecl
> > > CryptoPP::CheckedSetKey<class
> > > CryptoPP::BlockCipherFinal<0,class CryptoPP::DES::Base>
> > > >(class CryptoPP::BlockCipherFinal<0,class
> > > CryptoPP::DES::Base> *,enum CryptoPP::CipherDir,unsigned char
> > > const *,unsigned int,class CryptoPP::NameValuePairs const &)"
> > > ([EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@@
> > > @CryptoPP@@@CryptoPP@@[EMAIL PROTECTED]@[EMAIL PROTECTED]
> > > [EMAIL PROTECTED]@@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@0@@Z)
> > > already defined in test.obj test error LNK2005: "void __cdecl
> > > CryptoPP::CheckedSetKey<class
> > > CryptoPP::BlockCipherFinal<0,class CryptoPP::DES::Base>
> > > >(class CryptoPP::BlockCipherFinal<0,class
> > > CryptoPP::DES::Base> *,enum CryptoPP::CipherDir,unsigned char
> > > const *,unsigned int,class CryptoPP::NameValuePairs const &)"
> > > ([EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@@
> > > @CryptoPP@@@CryptoPP@@[EMAIL PROTECTED]@[EMAIL PROTECTED]
> > > [EMAIL PROTECTED]@@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@0@@Z)
> > > already defined in test.obj test error LNK2005: "void __cdecl
> > > CryptoPP::CheckedSetKey<class
> > > CryptoPP::BlockCipherFinal<0,class CryptoPP::DES::Base>
> > > >(class CryptoPP::BlockCipherFinal<0,class
> > > CryptoPP::DES::Base> *,enum CryptoPP::CipherDir,unsigned char
> > > const *,unsigned int,class CryptoPP::NameValuePairs const &)"
> > > ([EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@@
> > > @CryptoPP@@@CryptoPP@@[EMAIL PROTECTED]@[EMAIL PROTECTED]
> > > [EMAIL PROTECTED]@@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@0@@Z)
> > > already defined in test.obj test error LNK2005: "void __cdecl
> > > CryptoPP::CheckedSetKey<class
> > > CryptoPP::BlockCipherFinal<0,class CryptoPP::DES::Base>
> > > >(class CryptoPP::BlockCipherFinal<0,class
> > > CryptoPP::DES::Base> *,enum CryptoPP::CipherDir,unsigned char
> > > const *,unsigned int,class CryptoPP::NameValuePairs const &)"
> > > ([EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@@
> > > @CryptoPP@@@CryptoPP@@[EMAIL PROTECTED]@[EMAIL PROTECTED]
> > > [EMAIL PROTECTED]@@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@0@@Z)
> > > already defined in test.obj
> > >
> > > Is there any future plan to add workaround for Managed C++ or
> > > someone who already tried it?
> > >
> > >
> > >
> > > Ken
> > >
> > >
> 


Reply via email to