none
can ref class be used in non winrt project?

    Question

  • can I use ref class in a win32 c++ project?   I would like to experiment with the CX features in Windows 7 COM programmaing.

    thanks,

    Thursday, June 07, 2012 5:01 PM

Answers

  • It does implement automatic reference counting but there's more than that. For example such classes can be instantiated by non C++ code, this is done through a "activation factory" which resembles the class factory found in COM but it's different. If you try to create a dll that contains C++/CX classes you'll see that it depends on vccorlib.dll and that in turn depends on WinRT specific functions like RoInitialize, RoGetActivationFactory etc.
    • Marked as answer by Steve Richter Thursday, June 07, 2012 7:15 PM
    Thursday, June 07, 2012 7:11 PM

All replies

  • A ref class (as in C++/CX) requires WinRT and WinRT is only present in Win8. So no way that will work on Win7, WinRT is not COM despite having a lot of things in common.

    Thursday, June 07, 2012 5:29 PM
  • A ref class (as in C++/CX) requires WinRT ...

    I am getting the impression that a CX ref class is one that implements automatic reference counting on the pointers to instances of the ref class.  If that is the case, then why would the compiler need WinRT to maintain the reference count?

    Thursday, June 07, 2012 7:02 PM
  • It does implement automatic reference counting but there's more than that. For example such classes can be instantiated by non C++ code, this is done through a "activation factory" which resembles the class factory found in COM but it's different. If you try to create a dll that contains C++/CX classes you'll see that it depends on vccorlib.dll and that in turn depends on WinRT specific functions like RoInitialize, RoGetActivationFactory etc.
    • Marked as answer by Steve Richter Thursday, June 07, 2012 7:15 PM
    Thursday, June 07, 2012 7:11 PM