Click to See Complete Forum and Search --> : can unmanaged code be verifiable?


Justis
November 20th, 2003, 05:37 AM
I have got some C++ code that uses STL containers.
I need to use that code from a C# application, so compiled it as a .NET assembly.
As I wish to run the project on a web environment, the DLL must be verifiable.
As far as I understand, unless it's managed, it cant be verifiable.
One idea I had was to use System.Collections containers instead of the STL containers. As I dont want to make changes to the original code, I thought I could just create wrappers for the STL containers.
That approach didnt quite work, as I cannot provide the STL interface for my new containers, for reasons such as being unable to override the * and -> operators. (It's not allowed in managed code.)
Has anyone got a better (working) idea, or knows of an already existing solution to this problem?

Cheers,
g.

p.s.
Alternatively, is there a way of making unmanaged code verifiable?

vicodin451
November 20th, 2003, 07:37 AM
Originally posted by Justis
Alternatively, is there a way of making unmanaged code verifiable?

MSDN,
"Managed Extensions for C++ Concepts"
"Producing Verifiable Components with Managed Extensions for C++"

The following guidelines will help you author components that can be compiled into a verifiable component:

-Only fully managed constructs (not unmanaged classes, unmanaged pointers, and unmanaged arrays) are used


"Language Enhancements and Simplified GUI Development Enrich Your C++ Apps"

There are several steps involved in making a library verifiable; the most important involves writing code that will not fail verification. Thus, you cannot use __nogc types or unmanaged pointers. You should be wary of using interior pointers in your code because although you can assign and dereference them, if arithmetic is performed on them, the code will not be verifiable. Exceptions must be managed objects, so you cannot throw primitive types.
Of course, a verifiable assembly should not use unmanaged code of any kind. This means you should not be bringing in code through static libraries, though you can use platform invoke. This also discounts the use of the CRT so you have to use the linker switch /noentry. Also be wary of casts: you cannot use static_cast<> for downcasts between class types and you should never use reinterpret_cast<> because it will produce unverifiable code. Keywords like __asm, __try, and __except are used with unmanaged code, so they are not allowed and clearly #pragma unmanaged is also not allowed.

Justis
November 20th, 2003, 07:42 AM
thanks for that.
i guess re-writting the code in inevitable.
j.