简体   繁体   English

在哪里存储在C ++ dll中使用的.properties文件

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

I created a .properties file that contains a few simple key = value pairs. 我创建了一个.properties文件,其中包含一些简单的key = value对。 I tried it out from a sample c++ console application, using imported java classes, and I was able to access it, no problem. 我使用导入的Java类从示例c ++控制台应用程序中进行了尝试,并且可以访问它,没问题。

Now, I am trying to use it in the same way, from a C++ dll, which is being called by another (unmanaged) c++ project. 现在,我正在尝试以相同的方式从另一个(非托管)c ++项目调用的C ++ dll中使用它。

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 TIA

As you are mentioning "DLL" i guess, that you are using MS Windows. 当您提到“ DLL”时,我想您正在使用MS Windows。 Finding a file there from a DLL, and independently from the logged on user is a restricted item. 从DLL中找到文件,并且独立于登录用户,这是受限制的项目。 The best way is to store the file in a path assembled from the environment variable ALLUSERSPROFILE . 最好的方法是将文件存储在由环境变量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 >. 您的应用程序数据应驻留在名为<MyCompany>或<MyApplicationsName>的私有子目录中。 Type 类型

echo %ALLUSERSPROFILE%

on a windows command line prompt to find out the actual location on a machine. 在Windows命令行提示符下找到计算机上的实际位置。

Store your data in ie: 将数据存储在即:

%ALLUSERSPROFILE%\MyApp\

Your dll can then query the location of ALLUSERSPROFILE using getenv: 然后,您的dll可以使用getenv查询ALLUSERSPROFILE的位置:

char *allUsersData = getenv("ALLUSERSPROFILE");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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