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. Dynamically set PATH variable in application

Dynamically set PATH variable in application

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionannouncement
5 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.
  • W Offline
    W Offline
    Wim Jans
    wrote on last edited by
    #1

    I have this situation where I have to dynamically set the PATH variable used by the application. Imagine I have 2 versions of mylib.dll: c:\version1.0\mylib.dll c:\version1.1\mylib.dll My PATH variable is c:\version1.1; c:\version1.0 Now, my application links to mylib.lib, so whenever I startup my application, it is looking for the mylib.dll based on my PATH settings. What I want to accomplish is to give the user the possibility to specify which version of the dll is going to be used by the application (via a dialog box). So I thought the solution was to overrule the default PATH variable used by the application by my own one (c:\version1.0\mylib.dll needs to be used). Is this possible? How to accomplish this? Thanks in advance Wim

    S D V 3 Replies Last reply
    0
    • W Wim Jans

      I have this situation where I have to dynamically set the PATH variable used by the application. Imagine I have 2 versions of mylib.dll: c:\version1.0\mylib.dll c:\version1.1\mylib.dll My PATH variable is c:\version1.1; c:\version1.0 Now, my application links to mylib.lib, so whenever I startup my application, it is looking for the mylib.dll based on my PATH settings. What I want to accomplish is to give the user the possibility to specify which version of the dll is going to be used by the application (via a dialog box). So I thought the solution was to overrule the default PATH variable used by the application by my own one (c:\version1.0\mylib.dll needs to be used). Is this possible? How to accomplish this? Thanks in advance Wim

      S Offline
      S Offline
      Steve Thresher
      wrote on last edited by
      #2

      Could you dynamically link to the DLL and use LoadLibrary() to specify the path for the DLL? Systems AXIS Ltd - Software for Business ...

      W 1 Reply Last reply
      0
      • S Steve Thresher

        Could you dynamically link to the DLL and use LoadLibrary() to specify the path for the DLL? Systems AXIS Ltd - Software for Business ...

        W Offline
        W Offline
        Wim Jans
        wrote on last edited by
        #3

        Hello, I'm afraid that is not possible. Well, it might be possible, but the problem is that there are a lot of dll's invloved, and the references change over time. So I really need to stick to the .lib usage.

        1 Reply Last reply
        0
        • W Wim Jans

          I have this situation where I have to dynamically set the PATH variable used by the application. Imagine I have 2 versions of mylib.dll: c:\version1.0\mylib.dll c:\version1.1\mylib.dll My PATH variable is c:\version1.1; c:\version1.0 Now, my application links to mylib.lib, so whenever I startup my application, it is looking for the mylib.dll based on my PATH settings. What I want to accomplish is to give the user the possibility to specify which version of the dll is going to be used by the application (via a dialog box). So I thought the solution was to overrule the default PATH variable used by the application by my own one (c:\version1.0\mylib.dll needs to be used). Is this possible? How to accomplish this? Thanks in advance Wim

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Wim Jans wrote: So I thought the solution was to overrule the default PATH variable used by the application by my own one (c:\version1.0\mylib.dll needs to be used). Is this possible? How to accomplish this? SetEnvironmentVariable() comes to mind.


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          1 Reply Last reply
          0
          • W Wim Jans

            I have this situation where I have to dynamically set the PATH variable used by the application. Imagine I have 2 versions of mylib.dll: c:\version1.0\mylib.dll c:\version1.1\mylib.dll My PATH variable is c:\version1.1; c:\version1.0 Now, my application links to mylib.lib, so whenever I startup my application, it is looking for the mylib.dll based on my PATH settings. What I want to accomplish is to give the user the possibility to specify which version of the dll is going to be used by the application (via a dialog box). So I thought the solution was to overrule the default PATH variable used by the application by my own one (c:\version1.0\mylib.dll needs to be used). Is this possible? How to accomplish this? Thanks in advance Wim

            V Offline
            V Offline
            Vi2
            wrote on last edited by
            #5

            Look at the "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" entry in Registry. It's the modern approach now. You may use it for your purpose. For example, HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\someserver.exe @="S:\SRV7\Run\Release\bin\someserver.exe" "Path"="S:\SRV7\Run\Release\bin\;S:\SRV7\Run\Release\dll\" NOTE There is the separator ";" between pathes. With best wishes, Vita

            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