PC Review


Reply
Thread Tools Rate Thread

Is COM considered 'unsafe' code

 
 
Elidel
Guest
Posts: n/a
 
      11th Feb 2005

Is the use of a COM object in a c# program considered 'unsafe' code ?

Does the method that calls the COM object need the 'unsafe' keyword ?

Is code that calls a COM object considered unmanaged?

Is 'unsafe' code the same as unmanaged code ?
 
Reply With Quote
 
 
 
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      11th Feb 2005
Unsafe code is not the same as unmanaged code. Unsafe mean that pointers
will be used. You can have for example an array and performs memory
manipulation on it with a pointer: this code is totally managed but is
unsafe because a pointer is involved.

For COM object, you do not make direct call to it but instead make call to
the COM Interoperability assembly; so even if you have a method that make
*call* to a COM object, this method is still safe because it doesn't make
the real call to the COM object itself.

For a more accurate description of managed data, unmanaged code and unsafe
code, you can start by reading the following short document and after that,
search the web for "interoperability" :

http://www.intel.com/software/produc...cs/interop.pdf

S. L.

"Elidel" <(E-Mail Removed)> wrote in message
news:w3XOd.5620$(E-Mail Removed)...
>
> Is the use of a COM object in a c# program considered 'unsafe' code ?
>
> Does the method that calls the COM object need the 'unsafe' keyword ?
>
> Is code that calls a COM object considered unmanaged?
>
> Is 'unsafe' code the same as unmanaged code ?



 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      11th Feb 2005
1. Yes. A COM object does not run under the CLR. It is not managed,
therefore it is unsafe.

2. I'm not sure. Someone smarter than I am can tell you whether the
method that calls the COM object needs the 'unsafe' keyword. I know
that the code that calls the automatically-generated Interop.dll does
_not_ need the 'unsafe' keyword. However, if you're writing your own
interop, I don' t know.

3. No. .NET code that calls a COM object is managed because it runs
under the CLR (all .NET code is compiled to IL and runs under the CLR).
"Unmanaged" refers to code running native on your PC, outside the
bounds of the CLR.

4. No. All unmanaged code is unsafe. However, some managed code,
running under the CLR, can also be unsafe. This is what the 'unsafe'
keyword is for: to signal to the compiler that you know you are about
to use language constructs that may bypass security checks and are
therefore 'unsafe'.

However, all non-.NET (unmanaged) code runs native on the machine, not
under the CLR, so it cannot be subject to the CLR's security framework,
and is therefore by definition 'unsafe'.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is it possible to mark my CLR function as UNSAFE in code or visual studio anywhere so that wehn vs deploys, it creates unsafe assembly? (instead of me having to manualy deploy in tsql!) DR Microsoft ADO .NET 3 8th Nov 2007 06:34 PM
visual studio 2005 unsafe code may only appear if compiling with /unsafe rockdale Microsoft ASP .NET 3 3rd Nov 2006 05:45 PM
Is COM considered 'unsafe' code Elidel Microsoft Dot NET 2 11th Feb 2005 06:49 AM
On win XP - OE removed attachments which it considered unsafe? JonLoh Windows XP Help 3 30th May 2004 04:56 PM
ItemsCB is considered unsafe object when viewing Contacts folder Jerome Henriksen Microsoft Outlook Program Addins 2 22nd Aug 2003 08:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:21 PM.