Could not open file from C ++ DLL

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

Thanks, Rakesh.

+4
source share
3 answers

The location of the dll file does not matter. The open path must contain the full path or the file will be open for your current application working directory.

+8
source

If you use relative paths, the location of your data.txt file should be relative to the location of the process loading the DLL.

+1
source

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

0
source

Source: https://habr.com/ru/post/1302839/


All Articles