471,120 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,120 software developers and data experts.

/clr:safe

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
Jun 27 '08 #1
1 1398
ajk wrote:
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#.

--
J.
http://symbolsprose.blogspot.com
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Herby | last post: by
8 posts views Thread by Gary Nastrasio | last post: by
reply views Thread by vishal.nagota | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.