Hi,
I would like to get the value of “%ProgramFiles(x86)%” inside a template. I even thought this should be easy
I thought that the following would work:
#GROUP(%oGetProgramFilesX86)
#DECLARE(%jProgramFiles)
#SET(%jProgramFiles,EVALUATE('%ProgramFiles(x86)%'))
#!
#! If OS is 32bits, we need to check %ProgramFiles% instead....
#IF(%jProgramFiles = '%ProgramFiles(x86)%')
#SET(%jProgramFiles,EVALUATE('%ProgramFiles%'))
#ENDIF
#RETURN(%jProgramFiles)
But that, or various variations of that I have tried, didn’t work.
Hi,
I am exploring this because noyantis codejock templates (version 6) go to a sub-folder under “%ProgramFiles(x86)%” to get the activex’s license codes.
That doesn’t work on my machine because my windows is in Spanish. So instead of
“c:\program files (x86)” mine is “c:\archivos de programa (x86)”. In the end, I have to enter each control’s license manually for each application that uses the templates (as far as I can tell).
This problem got me wondering about how to get environment variables from inside the templates.
Anything that is returned by a windows api will need to be called using the #RunDll, so if you want to call (D)COM+ objects, you’ll need to write a (D)COM+ dll in clarion first then call it from the template using #RunDLL.
Thats a good point and there’s a couple ways of doing it.
The Redirection file can be used to store macro symbols, but you would need to parse the redirection file into a template, and then process the symbols in template code which is a lot more work than the other solutions suggested below.
The other way is using the template code itself and there are a couple of ways to do that. #Equate(%MyProgramFilesPath,‘c:\archivos de programa (x86)’)
or #Declare(%MyProgramFilesPath) #Set(%MyProgramFilesPath,‘c:\archivos de programa (x86)’)
Can you use GETREG from the template language ?
If so, you could read HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir (x86)
As you can see, it’s not much source at all.
Don’t forget to alter the .EXP
If you want to read an Environment Variable in CW
MAP
MODULE('APIs')
! I am pretty sure I got this Arnor Baldvinson in the 90s
GetEnvironmentVariable( |
*CSTRING lpName, | !// address of environment variable name
*CSTRING lpBuffer, | !// address of buffer for variable value
ULONG nSize), | !// size of buffer, in characters
ULONG, RAW, PASCAL, |
NAME('GetEnvironmentVariableA')
END
END
GetEnvVar PROCEDURE(STRING pEnvironmentVariable)!!,String
Dw ULONG
En CSTRING(256)
Rn CSTRING(256)
S ULONG
CODE
En = CLIP(pEnvironmentVariable)
Rn = ''
S = SIZE(Rn)
Dw = GetEnvironmentVariable(En,Rn,S)
RETURN Rn