简体   繁体   中英

where to store .properties file for use in c++ dll

I created a .properties file that contains a few simple key = value pairs. I tried it out from a sample c++ console application, using imported java classes, and I was able to access it, no problem.

Now, I am trying to use it in the same way, from a C++ dll, which is being called by another (unmanaged) c++ project.

For some reason, the file is not being accessed.

Maybe my file location is wrong. Where should I be storing it?

What else might be the issue?

TIA

As you are mentioning "DLL" i guess, that you are using MS Windows. Finding a file there from a DLL, and independently from the logged on user is a restricted item. The best way is to store the file in a path assembled from the environment variable ALLUSERSPROFILE . This is the only location that is equal to all users and where all users usually have write access. Your applications data should reside in a private subdirectory named like < MyCompany > or < MyApplicationsName >. Type

echo %ALLUSERSPROFILE%

on a windows command line prompt to find out the actual location on a machine.

Store your data in ie:

%ALLUSERSPROFILE%\MyApp\

Your dll can then query the location of ALLUSERSPROFILE using getenv:

char *allUsersData = getenv("ALLUSERSPROFILE");

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