locked
Using System classes

    Question

  • I'm trying to use a supported .NET class in System::IO::Compression, but the compiler complains that the System namespace does not exist, even though Object Browser shows it.

    The docs here state that "If you're developing a Windows Metro style app, your project automatically
    references all of the Windows 8 Consumer Preview SDK and the .NET Framework" (http://msdn.microsoft.com/en-us/library/hh708954(v=vs.110).aspx), but apparently not in my case.

    How do I fix this?

    Wednesday, April 11, 2012 4:37 PM

Answers

  • Yes, you could write a C# WinRT component and call that from your C++ app. You can pass WinRT types (either the StorageFile or the IRandomAccessStream) into the component. See Creating Windows Runtime Components in C# and Visual Basic

    When you call StorageFile.OpenAsync you will get an IRandomAccessStream back. Your .Net code can convert its IInputStream component to a .Net System.IO.Stream with System.IO's AsStreamForRead extension property.

    --Rob

    • Marked as answer by cdunford Thursday, April 12, 2012 6:29 PM
    Thursday, April 12, 2012 4:55 PM
    Owner

All replies

  • Metro style apps written using C++/Cx are native applications and do not use the .Net framework.

    If you want to write your Metro style app with .Net you need to use C# or VB.

    If you scope the object browser to your C++ solution then it won't list System::IO::Compression. That will be listed if you include .Net for Metro style apps, but again that requires writing the app with the .Net framework.

    --Rob

    Wednesday, April 11, 2012 8:46 PM
    Owner
  • C# is out for the app. Can we write a C# WinRT component to access the stuff from System.IO.Compression and use that from the app? I looked at this a little, and I see how to create the WinRT component, but it's not clear how information gets passed back and forth. For example, the app would get a StorageFile from the user via the WinRT file picker, but the .NET class in question needs a Stream. Is there any guidance for this kind of issue?

    Thursday, April 12, 2012 2:40 AM
  • Yes, you could write a C# WinRT component and call that from your C++ app. You can pass WinRT types (either the StorageFile or the IRandomAccessStream) into the component. See Creating Windows Runtime Components in C# and Visual Basic

    When you call StorageFile.OpenAsync you will get an IRandomAccessStream back. Your .Net code can convert its IInputStream component to a .Net System.IO.Stream with System.IO's AsStreamForRead extension property.

    --Rob

    • Marked as answer by cdunford Thursday, April 12, 2012 6:29 PM
    Thursday, April 12, 2012 4:55 PM
    Owner
  • Thanks, you are definitely da man.

    I had found the guide to creating WinRT components in C#, but information on passing the various types around and on converting between WinRT classes and .NET classes is extraordinarily hard to locate.

    Thanks again.

    Thursday, April 12, 2012 6:29 PM
  • BTW: as to the goal of your question (Compression) rather than the means (.Net), look at the Windows::Storage::Compression namespace.

    --Rob

    Sunday, April 15, 2012 6:27 PM
    Owner
  • Yes, we looked at Windows::Storage::Compression, but it doesn't have the functionality we need. We would have had to write a lot of code to do what the .Net classes already do.

    Incidentally, one of the things that could be beefed up in the documentation is how to pass values between C++ and C# WinRT components. It took us quite a while, for example, to figure out how to get a usable date from a DateTimeOffset value. It shows up on the C++ side basically as a big number with no methods, and we couldn't find any documentation that explains what to do with it. We eventually guessed the answer, but it took some time we could have put to better use.

    Sunday, April 15, 2012 7:30 PM