简体   繁体   中英

Unable to open file from C++ DLL

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.

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.

如果使用相对路径,则data.txt文件的位置必须相对于加载DLL的进程的位置。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM