By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,965 Members | 1,468 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,965 IT Pros & Developers. It's quick & easy.

Help me understand

P: n/a
Hello,

I did some experiments with VC++ 2005, and some ILDasm. Please tell me
if I have understood the concepts of C++ programming under .NET, since
I'm a bit confused!
--
There are 4 types of classes in VC++/CLI:

Unmanaged classes (i.e. normal classes compiled in a unmanaged source
or dll , the code is unmanaged and CPU native). Accessible from C++/CLI
classes but only with a reference (pointer), require a
managed/unmanaged transition for each function call.

Native classes
Standard C++ classes that are compiled with /CLR enabled. These are
marked as native, use the same syntax as standard c++, but compile to
IL (and use the IL CRT). These are not accessible from C#/VB, etc...
but only from C++. Allow for a CLR:Pure compilation, and the code
generated is effectively IL. (you can use framework classes). When an
unmanaged function is called a IJW stub is used.
I don't know if the term "native" is appropriate because on previous
versions it was used as synonym of "unmanaged". Anyway, using ILDasm I
see the "native" tag and IL code.

Value classes
Are .NET classes that can be defined only from C++/CLI, but can be
*used* from other languages too. Are effectively .NET classes value
classes, but could not be instantiated from C# VB. These suffer of many
limitations, so the port of existing C++ classes is not really
confortable.

Ref classes, are "ufficial" .NET classes , used in C++/VB, are accessed
with handles and garbage collected, bla bla bla
In C++ you can use Ref classes by value (and in C# it generates a
different syntax), anyway you need an explicit contructor and
copy/constructor.
--
It is correct? I'm a little confused about native classes. The lack of
value class support in C#/VB is not really good, because it makes
harder to port existing C++ code....
>From what I've understood, Native classes are the key feature to avoid
managed/unmanaged transitions and to port easily your existing code at
least into CLI.... (and that is REALLY good)

Tell me if I'm wrong...
Thanks and sorry for my English!!
QbProg

Dec 14 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Regarding ref vs value classes and comparison to C# and VB:
ref class -equivalent to C# or VB 'class'
value class -equivalent to C# or VB 'struct'

Note that the C++ 'ref struct' and 'value struct' are not required to
represent C# or VB entities. 'struct' in C++ is identical to a C++ class
except for the default access level.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"QbProg" wrote:
Hello,

I did some experiments with VC++ 2005, and some ILDasm. Please tell me
if I have understood the concepts of C++ programming under .NET, since
I'm a bit confused!
--
There are 4 types of classes in VC++/CLI:

Unmanaged classes (i.e. normal classes compiled in a unmanaged source
or dll , the code is unmanaged and CPU native). Accessible from C++/CLI
classes but only with a reference (pointer), require a
managed/unmanaged transition for each function call.

Native classes
Standard C++ classes that are compiled with /CLR enabled. These are
marked as native, use the same syntax as standard c++, but compile to
IL (and use the IL CRT). These are not accessible from C#/VB, etc...
but only from C++. Allow for a CLR:Pure compilation, and the code
generated is effectively IL. (you can use framework classes). When an
unmanaged function is called a IJW stub is used.
I don't know if the term "native" is appropriate because on previous
versions it was used as synonym of "unmanaged". Anyway, using ILDasm I
see the "native" tag and IL code.

Value classes
Are .NET classes that can be defined only from C++/CLI, but can be
*used* from other languages too. Are effectively .NET classes value
classes, but could not be instantiated from C# VB. These suffer of many
limitations, so the port of existing C++ classes is not really
confortable.

Ref classes, are "ufficial" .NET classes , used in C++/VB, are accessed
with handles and garbage collected, bla bla bla
In C++ you can use Ref classes by value (and in C# it generates a
different syntax), anyway you need an explicit contructor and
copy/constructor.
--
It is correct? I'm a little confused about native classes. The lack of
value class support in C#/VB is not really good, because it makes
harder to port existing C++ code....
From what I've understood, Native classes are the key feature to avoid
managed/unmanaged transitions and to port easily your existing code at
least into CLI.... (and that is REALLY good)

Tell me if I'm wrong...
Thanks and sorry for my English!!
QbProg

Dec 15 '06 #2

P: n/a


On 14 déc, 23:24, "QbProg" <tho...@gmail.comwrote:
Hello,

I did some experiments with VC++ 2005, and some ILDasm. Please tell me
if I have understood the concepts of C++ programming under .NET, since
I'm a bit confused!
--
<snip>
Value classes
Are .NET classes that can be defined only from C++/CLI, but can be
*used* from other languages too. Are effectively .NET classes value
classes, but could not be instantiated from C# VB. These suffer of many
limitations, so the port of existing C++ classes is not really
confortable.

Ref classes, are "ufficial" .NET classes , used in C++/VB, are accessed
with handles and garbage collected, bla bla bla
In C++ you can use Ref classes by value (and in C# it generates a
different syntax), anyway you need an explicit contructor and
copy/constructor.
Value classes are full fledged .NET citizens, and can be created in
other .NET languages. They are called "struct" in C# and "Structure" in
VB.NET. They indeed have some limitations compared to classes, but also
some advantages (eg, they are allocated on the stack, not on the manaed
heap). Anyway, the difference between those 2 types is defined by the
..NET Runtime, and it is not C++ specific in any way.
It is correct? I'm a little confused about native classes.
Why? You can simply see them as usual, normal C++ classes that are
compiled to a different assembly language... Anyway, your wording for
"unmanaged" versus "native" is not official, but if it helps you....
The lack of
value class support in C#/VB is not really good, because it makes
harder to port existing C++ code....
Value classes *ARE* supported in C# or VB !!!

To help you understand those things, you could use .NET Reflector
(Google for it) instead of IldAsm. This tool can dissasemble IL code
and show it as either C# or VB.NET source code. This may help you
understand better what the C++ compiler generates when calling it with
/clr.

Arnaud
MVP - VC

Dec 15 '06 #3

P: n/a


On 14 déc, 23:24, "QbProg" <tho...@gmail.comwrote:
Hello,

I did some experiments with VC++ 2005, and some ILDasm. Please tell me
if I have understood the concepts of C++ programming under .NET, since
I'm a bit confused!
--
<snip>
Value classes
Are .NET classes that can be defined only from C++/CLI, but can be
*used* from other languages too. Are effectively .NET classes value
classes, but could not be instantiated from C# VB. These suffer of many
limitations, so the port of existing C++ classes is not really
confortable.

Ref classes, are "ufficial" .NET classes , used in C++/VB, are accessed
with handles and garbage collected, bla bla bla
In C++ you can use Ref classes by value (and in C# it generates a
different syntax), anyway you need an explicit contructor and
copy/constructor.
Value classes are full fledged .NET citizens, and can be created in
other .NET languages. They are called "struct" in C# and "Structure" in
VB.NET. They indeed have some limitations compared to classes, but also
some advantages (eg, they are allocated on the stack, not on the manaed
heap). Anyway, the difference between those 2 types is defined by the
..NET Runtime, and it is not C++ specific in any way.
It is correct? I'm a little confused about native classes.
Why? You can simply see them as usual, normal C++ classes that are
compiled to a different assembly language... Anyway, your wording for
"unmanaged" versus "native" is not official, but if it helps you....
The lack of
value class support in C#/VB is not really good, because it makes
harder to port existing C++ code....
Value classes *ARE* supported in C# or VB !!!

To help you understand those things, you could use .NET Reflector
(Google for it) instead of IldAsm. This tool can dissasemble IL code
and show it as either C# or VB.NET source code. This may help you
understand better what the C++ compiler generates when calling it with
/clr.

Arnaud
MVP - VC

Dec 15 '06 #4

P: n/a
Thanks for the pointings!!
One last thing:
Why? You can simply see them as usual, normal C++ classes that are
compiled to a different assembly language... Anyway, your wording for
"unmanaged" versus "native" is not official, but if it helps you....
This is where I do not understand. From what I view from ILDast(I'll
try google net reflector soon :)
unmanaged classes are compiled to platform specific assembler code, but
NATIVE classes are still compiled to IL (i.e are not unmanaged but
accessible only from C++/CLI).
Native classes exists even with CLR:Pure (not unmanaged) and use a
modified version of the C Runtime.
I'm wrong?

QbProg

Dec 15 '06 #5

P: n/a

"QbProg" <th****@gmail.comwrote in message
news:11*********************@j72g2000cwa.googlegro ups.com...
Thanks for the pointings!!
One last thing:
>Why? You can simply see them as usual, normal C++ classes that are
compiled to a different assembly language... Anyway, your wording for
"unmanaged" versus "native" is not official, but if it helps you....

This is where I do not understand. From what I view from ILDast(I'll
try google net reflector soon :)
unmanaged classes are compiled to platform specific assembler code, but
NATIVE classes are still compiled to IL (i.e are not unmanaged but
accessible only from C++/CLI).
Native classes exists even with CLR:Pure (not unmanaged) and use a
modified version of the C Runtime.
I'm wrong?
You're not wrong about that.

You are wrong in thinking that only C++/CLI can generate value class types.
The equivalent in C# is the struct keyword.
>
QbProg

Dec 15 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.