473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Is COM considered 'unsafe' code


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 ?
Jul 21 '05 #1
2 1884
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'.

Jul 21 '05 #2
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" <ge********@wise.guy> wrote in message
news:w3*****************@newsread1.news.pas.earthl ink.net...

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 ?

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

61
by: Steven T. Hatton | last post by:
Stroustrup's view on classes, for the most part, seems to be centered around the notion of invariants. After a bit of adjusting to the use of yamt (yet another math term) in computer science, I...
3
by: Andre | last post by:
if I have an unsafe method that takes in two arrays, performs some operations and returns; I know that the garbage collector will not collect objects allocated inside the unsafe method. However, if...
8
by: | last post by:
Wel, I am rebuilding the VC# 2002 project that I have deployment problems with the 2003 version, hoping this solves the problems, but now I encounter this wierd bug??? If I have the project, and...
4
by: Jon Milner | last post by:
How do I declare that my code is unsafe? Sorry the help files at my University have not been installed!
17
by: Bradley1234 | last post by:
Sorry if this is obvious, but Ill ask... Is there a new way of using pointer operations in C# ? Ive got a Deitel book on C# that neither mentions the word "pointer" nor "unsafe" in the index....
4
by: CodeTyro | last post by:
My native language being C++, I've got a few questions that a couple of hours of searching on msdn didn't answer. First, when using unsafe code and pointers, what is the C# equivalent to the C++...
2
by: Elidel | last post by:
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?...
1
by: Z | last post by:
Hello, In my C# program I have a function that uses pointers. Is there a way to tell the compiler to compile only this function with the unsafe switch and compile the remaining project as safe...
2
by: NickP | last post by:
Hi there, I am currently moving my API declarations into relevant classes for Safe and Unsafe methods. My understanding is that unsafe methods are ones that require elevated security...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.