managed c++ vs unmanaged c++ 
Author Message
 managed c++ vs unmanaged c++

Hi Muhammad,

You can use unmanaged C++ classes in Managed C++, but not in C#.

In C#,  you can use Platform Invoke (DllImport) to call functions exported
from a Win32 Dlls, but are not able to instantiate a regular C++ class. To
workaround this scenario, you can either create a COM wrapper around your
class, and then import it to .NET via COM InterOp, or use Managed C++ to
wrap the class.

To use managed classes in unmanaged applications, you need to use COM
InterOp to export the classes. Also, notice that you should consider the
requirements of COM interop at design time. Managed types (class,
interface, struct, and enum) seamlessly integrate with COM types when you
adhere to the following guidelines:

1. Classes should implement interfaces explicitly
2. Managed types must be public.
3. Methods, properties, fields, and events must be public.
4. Types must have a public default constructor to be activated from COM.
5. Types cannot be abstract.

For more information about the guidelines, please refer to this article:

Qualifying .NET Types for Interoperation
http://www.*-*-*.com/
forinteroperation.asp

Hope this helps.

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Quote:

>Subject: managed c++ vs unmanaged c++
>Date: Tue, 3 Sep 2002 14:10:33 +0500
>Lines: 14
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

>Newsgroups:

microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.pub
lic.dotnet.framework.interop,microsoft.public.dotnet.framework.sdk,microsoft
public.dotnet.languages.vc
Quote:
>NNTP-Posting-Host: 202.163.100.130
>Path: cpmsftngxa10!tkmsftngp01!tkmsftngp08
>Xref: cpmsftngxa10 microsoft.public.dotnet.framework:25356

microsoft.public.dotnet.framework.interop:8225
microsoft.public.dotnet.framework.sdk:4448
microsoft.public.dotnet.languages.vc:14274 microsoft.public.dotnet.faqs:7266
Quote:
>X-Tomcat-NG: microsoft.public.dotnet.languages.vc

>If someone could help me with the following queries it will be highly
>appreciated ! please contact me on my email if some one is interested to
>provide help

>1)   What is the role of STL in Managed world?
>2)   Can we use Unmanaged Libraries ( Dll's / C++ classes / C++ classes
>encapsulated in dlls ) in Managed Applications? (and vice versa) if yes is
>there any           complete example available ?!





Mon, 28 Feb 2005 10:19:02 GMT  
 managed c++ vs unmanaged c++

Hi,

it would be good if you change your name from

to

like other people from MS...
Then more newsreader are able to display your name correctly...

XNews displays it only as "MS)"

--
Greetings
  Jochen



Mon, 28 Feb 2005 13:51:43 GMT  
 managed c++ vs unmanaged c++
Yep, it seems better now. Thank you so much, Jochen!

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Quote:
>Subject: OT: Name...



>User-Agent: Xnews/5.04.25
>X-Face:

#TA[Jae"bdx-+QGJx=d8Gi"CujilO8C4^r,6rco%?.Xk?;y`M?j&$Pmm>%[c!9kDW7m]C~N
bWutCC$vPTUW-"icn`nX:[F"N;mB9}]ABU?Y]tZwmSP{]!
Quote:
>Newsgroups: microsoft.public.dotnet.languages.vc
>Date: Wed, 11 Sep 2002 22:51:43 -0700
>NNTP-Posting-Host: 194.196.235.43
>Lines: 1        
>Path: cpmsftngxa08!tkmsftngp01!tkmsftngp10
>Xref: cpmsftngxa08 microsoft.public.dotnet.languages.vc:14120
>X-Tomcat-NG: microsoft.public.dotnet.languages.vc


>Hi,

>it would be good if you change your name from

>to

>like other people from MS...
>Then more newsreader are able to display your name correctly...

>XNews displays it only as "MS)"

>--
>Greetings
>  Jochen



Mon, 28 Feb 2005 22:01:49 GMT  
 managed c++ vs unmanaged c++


Quote:
> If someone could help me with the following queries it will be highly
> appreciated ! please contact me on my email if some one is interested to
> provide help

> 1)   What is the role of STL in Managed world?

C++ Users Journals recent issue just had an article about mixing STL and
managed C++.
Quote:
> 2)   Can we use Unmanaged Libraries ( Dll's / C++ classes / C++ classes
> encapsulated in dlls ) in Managed Applications? (and vice versa) if yes is
> there any           complete example available ?!





Tue, 01 Mar 2005 02:35:56 GMT  
 managed c++ vs unmanaged c++
Don't cross post, its not good manners.

Quote:
> 1)   What is the role of STL in Managed world?

It is used for templated containers for unmanaged types.

Quote:
> 2)   Can we use Unmanaged Libraries ( Dll's / C++ classes / C++ classes
> encapsulated in dlls ) in Managed Applications? (and vice versa) if yes is
> there any           complete example available ?!

Yes, managed C++ comes with a technology called It Just Works (called that
because it does). You don't have to do anything to use IJW other than use an
unmanaged static library, or call an exported DLL function. Using managed
types in unmanaged applications is a little more involved. There are two
ways to do this, the easiest way is to use regasm to register the .NET
assembly as a COM server and then use tlbexp to export the metadata as a
type library and use #import in your native C++ application so that you can
call the classes. The downside of this is that the .NET must be in the GAC
or you must use /codebase with regasm which 'fixes' the assembly to one
location on your hard disk. The other way that you can call .NET classes
from unmanaged C++ is to use the hosting interfaces. In affect you
explicitly load the CLR into your process, creating an AppDomain where you
can call .NET classes to load types and execute them. The downside of this
is that it is extremely tedious because many of the .NET classes have
overloaded methods, and .NET distinguishes between them using numerical
suffixes, and as far as I can tell there is no obvious way to tell which
overload corresponds to which suffix. Furthermore, most of the framework
classes are exported through COM as automation interfaces rather than dual
interfaces (there are good reasons for this, which I won't go into here)
which makes the coding tedious from C++.

Richard

--
Richard Grimes [MVP]
author: "Programming with Managed Extensions for Visual C++ .NET",
the Microsoft Press book about Managed C++



Tue, 01 Mar 2005 23:28:27 GMT  
 managed c++ vs unmanaged c++

Quote:
> > 2)   Can we use Unmanaged Libraries ( Dll's / C++ classes / C++ classes
> > encapsulated in dlls ) in Managed Applications? (and vice versa) if yes
is
> > there any           complete example available ?!



Yes, when you compile C++ with the /clr option, you are using the CLR as a
compiler backend (the C++ will emit IL instead of native machine code).

So you are able to almost anything you could do in C++ (including for
example, inlined assembly code) + interoperate with managed code, via __gc
classes.

David



Sun, 27 Mar 2005 04:48:45 GMT  
 managed c++ vs unmanaged c++
(inline)



Quote:

> > > 2)   Can we use Unmanaged Libraries ( Dll's / C++ classes / C++
classes
> > > encapsulated in dlls ) in Managed Applications? (and vice versa) if
yes
> is
> > > there any           complete example available ?!


> Yes, when you compile C++ with the /clr option, you are using the CLR as a
> compiler backend (the C++ will emit IL instead of native machine code).

> So you are able to almost anything you could do in C++ (including for
> example, inlined assembly code) + interoperate with managed code, via __gc
> classes.

Inlined code is converted to IL?? I thought managed C++ emitted x86 code?

- Show quoted text -

Quote:

> David



Tue, 12 Apr 2005 21:23:44 GMT  
 managed c++ vs unmanaged c++
Stu,

Quote:

> Inlined code is converted to IL??

Nope.

Quote:
> I thought managed C++ emitted x86 code?

Neither.

Normally, managed C++ code will be emitted as MSIL (or CIL, whatever you
prefer to call it). However, some methods, even in a #prama managed section,
cannot be emitted as IL. One of such cases is when it has inline assembly.

In These cases, the compiler will try to emit the method as an unmanaged
method. Obviously, there are cases where neither option is possible, in
which cases the compiler will emit an error.

--
Tomas Restrepo



Wed, 13 Apr 2005 01:23:31 GMT  
 managed c++ vs unmanaged c++
Ahhh, well, I live and learn.

Thanks!



Quote:
> Stu,

> > Inlined code is converted to IL??

> Nope.

> > I thought managed C++ emitted x86 code?

> Neither.

> Normally, managed C++ code will be emitted as MSIL (or CIL, whatever you
> prefer to call it). However, some methods, even in a #prama managed
section,
> cannot be emitted as IL. One of such cases is when it has inline assembly.

> In These cases, the compiler will try to emit the method as an unmanaged
> method. Obviously, there are cases where neither option is possible, in
> which cases the compiler will emit an error.

> --
> Tomas Restrepo




Sat, 23 Apr 2005 22:14:40 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. managed C++ wrapper around unmanaged C++ classes: causing StackOverflow exception

2. Performance of unmanaged C++ in a managed C++ app

3. Fatal Error C1010 in Mixing Managed C++ and Unmanaged C++ Code

4. Inherit unmanaged c++ classes from .Net platform (managed c++ or c#)

5. C# client crashs when calling into Managed C++ which calls unmanaged c++ function

6. How to pass a function pointer from Managed C++ to unmanaged c++

7. Managed C++ and Unmanaged C++ and Inheritance

8. Interoperability UnManaged C++, Managed C++, C#

9. How to call managed C++ DLL from unmanaged C++ EXE

10. debugging unmanaged c++ from a managed c++ class library

11. Visual form inheritance from base form implemented in C++ with Managed Extensions (migrated from unmanaged C++)

12. marshal an array from managed C++ to unmanaged C++

 

 
Powered by phpBB® Forum Software