none
Native or Managed or Mixed Mode - C++/CX code using a .NET class

    Question

  • I am building a WinService application in C++ as performance is very very critical. Down the line, I need to access a database, provide compression etc.... I realize that there aren't that many classes in MFC or any other native API from Microsoft like what .NET library has got to offer.

    Q1) Problem starts here: If I try to make use of .NET classes in my C++ application (now has to be C++/CX), what do I end up with? - A truly native compiled code or an application that will be hosted by the CLR or a mixed mode application?

    Q2) If it is a mixed mode application, wouldn't there be overheads transitioning from unmanaged to managed and vice verza

    Q3) This is very very fundamental question (please help me) - In a mixed mode application, would the main process (native) host the CLR ? 


    Tuesday, May 21, 2013 5:32 PM

Answers

  • If you want to do this for a normal windows service, you'll need to use C++/CLI, not C++/Cx.  (C++/CX is for Windows Store Apps)

    Q1) You end up with a mixed mode application if you compile with /clr, or a managed app if you use /clr:pure (unlikely)

    Q2) There is some overhead in the transition.  However, this is typically very minor compared to the latency with connecting to and pull data from a DB, etc, so it may or may not be an issue in those cases.

    Q3) This depends a bit on how you structure your application, but essentially, yes.  Your application will become a mixed mode application which is "mixed", so you have both a native and CLR startup, etc.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by S. Vasu Thursday, May 23, 2013 3:34 PM
    Tuesday, May 21, 2013 5:41 PM
  • Thank you.
     
    When you say C++ / CX is just for Win Store Apps only - I doubt it very much.
    Maybe in the future C++/CX will be used for non-store apps, but for now I beleive Reed's statement is correct.
     

    David Wilkinson | Visual C++ MVP
    • Marked as answer by S. Vasu Thursday, May 23, 2013 3:34 PM
    Thursday, May 23, 2013 10:58 AM

All replies

  • If you want to do this for a normal windows service, you'll need to use C++/CLI, not C++/Cx.  (C++/CX is for Windows Store Apps)

    Q1) You end up with a mixed mode application if you compile with /clr, or a managed app if you use /clr:pure (unlikely)

    Q2) There is some overhead in the transition.  However, this is typically very minor compared to the latency with connecting to and pull data from a DB, etc, so it may or may not be an issue in those cases.

    Q3) This depends a bit on how you structure your application, but essentially, yes.  Your application will become a mixed mode application which is "mixed", so you have both a native and CLR startup, etc.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by S. Vasu Thursday, May 23, 2013 3:34 PM
    Tuesday, May 21, 2013 5:41 PM

  • Thank you. 

    When you say C++ / CX is just for Win Store Apps only -  I doubt it very much.

    Wouldn't C++/CX be used in development of applications such as batch mode application or Winservice application or even a small utility that runs off a console.

    If you were to compare .Net's System.Security.Cryptography Namespace with WinRT Windows.Security.Cryptography it is quite obvious that there is a native implementation. To provide another example look at the Compression area: WinRT runtime (native) has gotWindows.Security.Cryptography and it is definitely going to be faster than what is avaiable in .NETs System.Security.Cryptography namespace. All the WinRT elements available in C++ /CX and of course other .NET language which will be slightly slower due to projections with winmd to guide them.

    May be that is where Microsoft wants to shift in the long run ... into WinRT (native) 

    C++/CX will be a super performer using the WinRT runtime (native) and we will be developing all kinds of apps using C++/CX with Windows 8 and later releases.



    • Edited by S. Vasu Thursday, May 23, 2013 10:59 AM
    Thursday, May 23, 2013 10:48 AM
  • Thank you.
     
    When you say C++ / CX is just for Win Store Apps only - I doubt it very much.
    Maybe in the future C++/CX will be used for non-store apps, but for now I beleive Reed's statement is correct.
     

    David Wilkinson | Visual C++ MVP
    • Marked as answer by S. Vasu Thursday, May 23, 2013 3:34 PM
    Thursday, May 23, 2013 10:58 AM
  • Thanks to all of you. Cleared up a lot of confusion. 

    C++/CX documentation page indeed states what you say..

    Visual C++ component extensions (C++/CX) is a set of extensions to the C++ language that enable the creation of Windows Store apps and Windows Runtime components in an idiom that is as close as possible to modern C++. Use C++/CX to write Windows Store apps and components .......

    Got to pound on C++ / CLI  now. But future for developers in C++ seems very rosy.


    Thursday, May 23, 2013 3:34 PM