Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. making file path generic

making file path generic

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pl_kode
    wrote on last edited by
    #1

    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.

    J T 2 Replies Last reply
    0
    • P pl_kode

      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.

      J Offline
      J Offline
      Jijo Raj
      wrote on last edited by
      #2

      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.

      P 1 Reply Last reply
      0
      • P pl_kode

        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.

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        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" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>

        1 Reply Last reply
        0
        • J Jijo Raj

          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.

          P Offline
          P Offline
          pl_kode
          wrote on last edited by
          #4

          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.

          M 1 Reply Last reply
          0
          • P pl_kode

            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.

            M Offline
            M Offline
            Manu Dev
            wrote on last edited by
            #5

            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

            P 1 Reply Last reply
            0
            • M Manu Dev

              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

              P Offline
              P Offline
              pl_kode
              wrote on last edited by
              #6

              Ok fine.. But how do I store the path of the file in the registry. How does it work. THANKS

              J 1 Reply Last reply
              0
              • P pl_kode

                Ok fine.. But how do I store the path of the file in the registry. How does it work. THANKS

                J Offline
                J Offline
                Jijo Raj
                wrote on last edited by
                #7

                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 use GetEnvironmentVariable() 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 use CRegKey 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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups