473,466 Members | 1,358 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1888
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.