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. can i use %windir% to get windows directory???

can i use %windir% to get windows directory???

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
2 Posts 2 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.
  • V Offline
    V Offline
    venadder
    wrote on last edited by
    #1

    Hi, I want to replace the hardcoded string by the path in %windir% in the following code #ifdef WIN32 CHAR CFM_INI_FILE[CFM_NAME_LEN] = "C:\\Winnt\\abc.ini"; #else CHAR CFM_INI_FILE[CFM_NAME_LEN] = "/Winnt/abc.ini"; #endif can I do that? I cannot use GetWindowsDirectory function because this code is in global space in a cpp file. My understanding is a function can be called only from within a function and not from global space. Please advice.. P.S. :- this code has to be in global space. If i put it in function and initialize there i have to make changes in over 60 files to make sure it is initialized before it is used.

    R 1 Reply Last reply
    0
    • V venadder

      Hi, I want to replace the hardcoded string by the path in %windir% in the following code #ifdef WIN32 CHAR CFM_INI_FILE[CFM_NAME_LEN] = "C:\\Winnt\\abc.ini"; #else CHAR CFM_INI_FILE[CFM_NAME_LEN] = "/Winnt/abc.ini"; #endif can I do that? I cannot use GetWindowsDirectory function because this code is in global space in a cpp file. My understanding is a function can be called only from within a function and not from global space. Please advice.. P.S. :- this code has to be in global space. If i put it in function and initialize there i have to make changes in over 60 files to make sure it is initialized before it is used.

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      It is possible to get the value of %windir% with several functions, amongst them

      char *getenv( const char *varname );

      but from what I understand in your msg, you do not want to use any initialisation, e.g. function call. So I am afraid that the answer to venadder wrote: can I do that? is : yes, you can, but it will unfortunately not be replaced at runtime with "C:\Winnt". :~ So, be ready to modify your 60 files X| ~RaGE();

      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