.NET Assembly and non-managed Objects

  • Thread starter Thread starter Gideon
  • Start date Start date
G

Gideon

hi all.
is it at all possible to compile some unmanaged c++ code into a .NET
assembly?
cheers.
 
is it at all possible to compile some unmanaged c++ code into a .NET
assembly?

Yes, the VC++ compiler supports mixing native and managed code.



Mattias
 
Hi Gideon

As mattias said it is possible. Brian was also right
about the unsafe keyword.

But the two answers are related to two different points.
First of all, wat exactly do you mean by unmanaged code.

Managed code is basically the code which runs under the
supervision of the CLR and is able to take advantage of
the various features that it provides, like memory
management or type verification. Example is a standard
C#/VB.Net program

UnManaged Code is basically the code that runs outside the
context of the CLR and examples are your typical Win32 or
COM programs

That said, Unsafe code is a cross between the managed and
unmanaged code. Like a managed code, it runs under the
supervision of the CLR, but like a unmanaged code it
allows you to access memory directly. Note that Unsafe
programming can be done ib C# only. You use the unsafe
keyword to tell the runtime that the code written inside
the block directly accesses memory and the fixed keyword
(lest the memory area that you are accessing directly be
moved by he Runtime GC Compacting process).

Now back to your question. Yes!! you can write unsafe code
in C#. As to unmanaged code are you talking about native
code. if so. yes again!!!!!. In fact if you look at the
assembly PE file. it contains 4 sections

The PE header
The CLR header
Metadata
IL

Here the PE Header is similar to the Common Object File
Format(COFF header). It contains the type of the
application(CUI/GUI/DLL). It also contains certain flags.
In addition for the assemblies that contain pure IL code
the bulk of info in the header is ignored. however if the
module contains native cpu code, the info about it is
stored in this header.

So .Net allows u to write and use managed/unmanaged/native
code and unsafe code

hth

regards,

sr
 
Back
Top