views:

55

answers:

2

Hi,

I need to work on converting a very huge c++ project to clr safe. The current c++ project has a lot of stuff from c++ like templates, generics, pointers, storage/stream, ole apis, zlib compression apis, inlines etc. Where can I find the datiled document for this type of conversion? Can you suggest some good book to refer to? If anyone of you have done such conversion, can I get some analysis from you?

Thanks

+1  A: 

The vast majority of native C++ is entirely valid C++/CLI, including templates, inlines, etc, except the CLR STL is rather slow compared to the BCL. Also, native C++ doesn't have generics, only templates.

The reality of compiling as C++/CLI is to check the switch and push compile, and wait for it to throw errors.

DeadMG
The vast majority of C++ is C++/CLI, but not "safe" C++/CLI. Anything that touches native classes or pointers is invalid in "safe" mode.
Billy ONeal
+2  A: 

I'll just cough up the MSDN Library article titled "How to: Migrate to /clr:safe

Visual C++ can generate verifiable components with using /clr:safe, which causes the compiler to generate errors for each non-verifiable code construct.

The following issues generate verifiability errors:

  • Native types. Even if it isn't used, the declaration of native classes, structures, pointers, or arrays will prevent compilation.
  • Global variables
  • Function calls into any unmanaged library, including common language runtime function calls
  • A verifiable function cannot contain a static_cast Operator for down-casting. The static_cast operator can be used for casting between primitive types, but for down-casting, safe_cast or a C-Style cast (which is implemented as a safe_cast) must be used.
  • A verifiable function cannot contain a reinterpret_cast operator (or any C-style cast equivalent).
  • A verifiable function cannot perform arithmetic on an interior_ptr. It may only assign to it and dereference it.
  • A verifiable function can only throw or catch pointers to reference types, so value types must be boxed before throwing.
  • A verifiable function can only call verifiable functions (such that calls to the common language runtime are not allowed, include AtEntry/AtExit, and so global constructors are disallowed).
  • A verifiable class cannot use Explicit.
  • If building an EXE, a main function cannot declare any parameters, so GetCommandLineArgs must be used to retrieve command-line arguments.
  • Making a non-virtual call to a virtual function.

Also, the following keywords cannot be used in verifiable code:

  • unmanaged and pack pragmas
  • naked and align __declspec modifiers
  • __asm
  • __based
  • __try and __except

I reckon that will keep you busy for a while. There is no magic wand to wave to turn native C++ into verifiable code. Are you sure this is worth the investment?

Hans Passant