/clr:safe

  • Thread starter Thread starter ajk
  • Start date Start date
A

ajk

Hi

I am doing a C++/CLI dll that is supposed to be fully managed code. I
was wondering what exactly is the criteria for the DLL to be 100%
fully managed and usuable from C#? Do I need to compile using /
clr:safe or is /clr enough?

The reason I need to know this is that I would like to use pin_ptr<>
for some type conversions i.e. bytes to say decimal but /clr:safe
doesn't allow me to do much with that pointer.

tia
ajk
 
ajk said:
I am doing a C++/CLI dll that is supposed to be fully managed code. I
was wondering what exactly is the criteria for the DLL to be 100%
fully managed and usuable from C#?

These are two different things. In fact, to be useful from C#, a DLL does
not have to be managed at all.
Do I need to compile using / clr:safe or is /clr enough?

/clr is enough if you just want to be able to call the DLL without interop
wrapping (as unmanaged code would require). Your public interface should be
restricted to managed types, manipulating only managed types. What you do
internally is then of no concern to the outside world.
The reason I need to know this is that I would like to use pin_ptr<>
for some type conversions i.e. bytes to say decimal but /clr:safe
doesn't allow me to do much with that pointer.
Using /clr:safe restricts you to constructs that allow the DLL to be an
assembly containing only managed code. There are speed and safety benefits
to this, but it is by no means a requirement to be able to use the code from
other managed assemblies.

In fact, there's really not much point to writing pure managed code in
C++/CLI unless you happen to really like C++: the strength of C++/CLI is
exactly that it can mix managed and unmanaged constructs and thus glue the
two worlds together. If you want pure managed code, you might as well use C#.
 
Back
Top