making file path generic
-
I have to read a property file to get the values from it. I am creating a generic DLL program were I have to put the path for this properties file in such a way that it can be accessed from anywere. At present I am hardcoding it like.. char path[]="c:\properties\file.properties" Now if the dll gets created with this path and the properties file is in another folder. how do I access it. Please help me with some suggestions. I have to make it generic. THANKS.
-
I have to read a property file to get the values from it. I am creating a generic DLL program were I have to put the path for this properties file in such a way that it can be accessed from anywere. At present I am hardcoding it like.. char path[]="c:\properties\file.properties" Now if the dll gets created with this path and the properties file is in another folder. how do I access it. Please help me with some suggestions. I have to make it generic. THANKS.
One simple alternative is Environment variables . Configure an Environment variable and set the path in it. Your application will be reading the file path from the env var. So that you can modify the filepath at anytime without modifying your application. You can also use registry for keeping the filepath. :) Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
I have to read a property file to get the values from it. I am creating a generic DLL program were I have to put the path for this properties file in such a way that it can be accessed from anywere. At present I am hardcoding it like.. char path[]="c:\properties\file.properties" Now if the dll gets created with this path and the properties file is in another folder. how do I access it. Please help me with some suggestions. I have to make it generic. THANKS.
pl_kode wrote:
At present I am hardcoding it like.. char path[]="c:\properties\file.properties"
Might be u could put your DLL in to C:\windows and C:\Windows\system32 folder. but that would be not right approach, if your are comfortable in COM, that you could make com dll. it would surly available, when ever you make the call with right interface.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>
-
One simple alternative is Environment variables . Configure an Environment variable and set the path in it. Your application will be reading the file path from the env var. So that you can modify the filepath at anytime without modifying your application. You can also use registry for keeping the filepath. :) Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
Now I do it in this way... char *prop_path; prop_path = getenv ("file.properties"); and get the following error.. error C2501: 'prop_path' : missing storage-class or type specifiers error C2040: 'prop_path' : 'int' differs in levels of indirection from 'char *' error C2440: 'initializing' : cannot convert from 'char *' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast How shud i get rid of them .please suggest.
-
Now I do it in this way... char *prop_path; prop_path = getenv ("file.properties"); and get the following error.. error C2501: 'prop_path' : missing storage-class or type specifiers error C2040: 'prop_path' : 'int' differs in levels of indirection from 'char *' error C2440: 'initializing' : cannot convert from 'char *' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style cast How shud i get rid of them .please suggest.
Which version of VC++ you are using? VS 2003 and above there are a lots of issues with cast between char* and wchar*. If you have a newer version try using getenv_s or wgetenv_s functions. I am using Visual studio 2002 and the following code runs sucessfully:
char* envVarVal;
envVarVal = getenv("PATH");
AfxMessageBox(envVarVal);In any case, be advised that getenv() and _putenv() only affect the environment variables for your own process. They do not add system wide accessable environment variable. In case you require that, instead of setting environment variables, try storing the path of the file in the registry.
only dead fish swim with the stream
-
Which version of VC++ you are using? VS 2003 and above there are a lots of issues with cast between char* and wchar*. If you have a newer version try using getenv_s or wgetenv_s functions. I am using Visual studio 2002 and the following code runs sucessfully:
char* envVarVal;
envVarVal = getenv("PATH");
AfxMessageBox(envVarVal);In any case, be advised that getenv() and _putenv() only affect the environment variables for your own process. They do not add system wide accessable environment variable. In case you require that, instead of setting environment variables, try storing the path of the file in the registry.
only dead fish swim with the stream
-
Ok fine.. But how do I store the path of the file in the registry. How does it work. THANKS
Since its a settig file i thought it won't be modified by your application. Thats why suggested to use env var because its easy to use. Other than
getenv()
you can also useGetEnvironmentVariable()
function. But if you want to update the filepath from your application, then registry will be the better choice as Manu.Dev suggested. You can useCRegKey
for registry operations which will make your life easier. See here how to use it - http://forums.devarticles.com/c-c-help-52/reading-the-registry-9764.html[^] Or else you can use Platform SDK registry functions - http://msdn.microsoft.com/en-us/library/ms724875(VS.85).aspx[^] Regards, Jijo._____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.