4

I have an application for which GUI is written in C# and the logic is written in C++ DLL. The DLL should open a file to read data from it. I have the data.txt file in the same folder as the DLL. When I call fopen("data.txt","r") the value returned is NULL. What could be the problem? Please help me in this regard.

Thanks, Rakesh.

Rakesh K
  • 8,237
  • 18
  • 51
  • 64

3 Answers3

8

The location of the dll file is not relevant. The path of your open must contain the complete path or the file will be opened to your applications current working directory.

DougS
  • 141
  • 1
1

If you use relative paths, the location of your data.txt file must be relative to the location of the process that loaded the DLL.

Kerido
  • 2,930
  • 2
  • 21
  • 34
0

Instead of using fopen, try OpenFile. It will probably also fail, but then you can call GetLastError() and know the reason.

Warpin
  • 6,971
  • 12
  • 51
  • 77