1

I have an application for which GUI is written in C# UWP and accessing the file logic is written in C++ DLL. The DLL should open a file to read data from it. I am trying to access the file from its location. When I call inFile.open("D:\\File\\readFile.txt", ios::in) the value returned is NULL.

To check if there is any problem with the file path, I have created a console application to access the file using the same way and it worked. What could be the problem?

fstream inFile;
inFile.open(filePath, ios::in);
if (!inFile.is_open()) 
{
    /* Display unable to read file*/
    return;
}

/* Perform operation on file */
inFile.close();
too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Ram Kishore
  • 119
  • 7
  • 1
    Possible duplicate of https://stackoverflow.com/questions/17337602/how-to-get-error-message-when-ifstream-open-fails. – Polyfun Aug 30 '18 at 12:07
  • @Polyfun its not a duplicate question. It is working in normal console application and doesn't work if done through UWP and DLL. – Ram Kishore Aug 30 '18 at 12:36
  • 1
    The link in my previous comment shows how to get more diagnostic information when the fsteam.open call fails. You need that to find out why the call is failing. It could be a permissions problem. – Polyfun Aug 30 '18 at 13:00
  • @Polyfun understood. And checked now. Says permission denied if accessed through UWP and C++ DLL. Works fine if accessed through console application. – Ram Kishore Aug 30 '18 at 13:17
  • 2
    @RamKishore In UWP, you cannot access the file through the path on drive. If you want to access a file from other libraries, you need to use `ms-appx:///` URI. Also see [this](https://stackoverflow.com/questions/48699649/how-to-access-content-from-a-net-standard-2-0-class-libary-from-uwp). This is not c++ though. – AVK Aug 30 '18 at 13:39
  • Thanks guys. Understood and it worked. – Ram Kishore Aug 31 '18 at 06:02

0 Answers0