Yes, the same way you use any unmanaged C++ in C# -- create managed
wrapper assembly around unmanaged C++ code. Managed C++ can link to
unmanaged C++ libraries, and C# can load managed C++ assemblies. There
are few tricks you need to do make sure CRT is initialized and managed
strings properly converted over to unmanaged memory (you don't want GC
to yank your string underneath you).
Best way is to reduce visibility of cryptopp code to C# as much as
possible, so it puts some data in and gets some data out. So no fancy
filter chains :(
Let me know if you need more details.
(But anyway, don't use C# -- C++ is much better :)).
There are several tutorials around.
Here is how to make and use managed assembly:
http://msdn.microsoft.com/en-us/library/ms235638.aspx
Here is how to use unmanaged code in it:
http://www.ondotnet.com/pub/a/dotnet/2003/03/03/mcppp2.html
(You might find better ones, I'm posting first remotely related things I
found -- google is your friend).
- build cryptopp as a static library
- make C++.Net assembly dll (class library) linked with cryptopp and
exporting your wrapper
- make wrapper class exporting functionality you need -- turn off
managed code by default (I think it is a project option or something)
and use __gc keyword to define your wrapper.
- include assembly into your C# project and use your wrapper
- ???
- profit!
So wrapper would be something like this:
public __gc class Wrapper
{
public:
System::String* DoubleRot13(System::String* input);
// ...
};
And in the function you will do the work. In C# you will call it like this:
String encrypted = Wrapper.DoubleRot13("bla bla bla");
Make sure you wrapper exports a way to initialize and terminate CRT --
C# doesn't do that, so you'll have to do it manually before first call
to unmanaged code, or suffer when cryptopp tries to use a static
variable or something.
void Wrapper::InitializeCRT() { __crt_dll_initialize(); }
void Wrapper::TerminateCRT() { __crt_dll_terminate(); }
If you want to convert managed String into unmanaged std::string you can
use that (not sure what will this do with actual Unicode though). Same
idea for any other datatypes you need to convert.
std::string ConvertString(String* input)
{
const wchar_t __pin* wch = PtrToStringChars(input);
int length = (input->Length+1)*2;
char *ch = new char[length];
bool result = wcstombs(ch, wch, length) != -1;
std::string output = ch;
delete ch;
return output;
}
There might be some specific compiler and linker flags you have to set,
but I don't remember now.