Open File within WinRT DLL RRS feed

  • Question

  • Hi, I am developing a WinRT DLL to access files. I use fopen() to do it but the returned pointer is always a nullptr, either reading or writting.

    Is this a permission issue? How to resolve it?


    • Edited by Greg Ma Thursday, October 20, 2011 7:44 AM
    Thursday, October 20, 2011 7:39 AM


All replies

  • The most likely cause here is that fopen uses API that is not allowed under WinRT. In general, direct file/folder access is not allowed in WinRT's sandboxed environment.


    The key point to remember is that WinRT apps cannot substitute existing desktop apps. There are far too many security and API restrictions that make this an impossibility.

    Thursday, October 20, 2011 11:53 AM
  • APIs that are not allowed in the WinRT partition should be guarded by defines; as such they should fail to compile (or exhibit as undefined symbols) as opposed to failing at runtime.

    Greg, where is the file are you trying to open?  Metro-style apps by design have a very limited scope of influence on the file system.  They can only access the application's temporary storage location, or locations that the user has designated as permissible.  (For example, you can access the pictures folder, but only if you have specified that particular Capability in your package manifest.)

    In addition, some file locations can only be accessed via metro brokered APIs.  You can access file paths in your application's install directory and temporary directory using CRT functions, but other locations (such as the Pictures folder) can only be accessed using brokered APIs.

    • Edited by Andy RichMicrosoft employee Monday, July 23, 2012 5:45 PM Mistaken information about which files the CRT APIs are capable of opening.
    Thursday, October 20, 2011 5:16 PM
  • Btw, you can use fopen in the application's temp folder.  Please see the following thread for an example of doing write operations in that folder:





    Thursday, October 20, 2011 8:30 PM
  • Thanks all of you, my problem is resolved by using file APIs to access application's temp folder.




    Friday, October 21, 2011 9:20 AM