Archive: value of user_var in a !define


value of user_var in a !define
Is there any possibility to put the value of user_var in a !define and vice versa?
StrCpy doesn't work with defines.

I have to call a function out of a DLL-file, that needs a !define as a parameter, but I have to read the value out of an INI-file before. ReadINIStr works only with a user_var.

At first, with a define right into the push-string (1. parameter for CallInstDLL) it looked like this (and worked fine):

!define XYZ
...
Push "$$$$XYZ$$$$=${XYZ}"
CallInstDLL Some.dll function


I tried it this way, but that doesn't work:

Var /GLOBAL setXYZ
ReadINIstr $setXYZ ...
...
Push "$$$$XYZ$$$$=$setXYZ"
CallInstDLL Some.dll function


I can't change the $-inferno because it is needed for the called function/DLL and the corresponding XML file.

Any ideas?

Try it like this:

Var /GLOBAL setXYZ
ReadINIstr $setXYZ ...
...
Strcpy $0 "$$$$XYZ$$$$=$setXYZ"
Push $0
CallInstDLL Some.dll function

(You may have to escape the $ inferno, especially if there is a variable $XYZ).

Originally posted by zackbuffo
I have to call a function out of a DLL-file, that needs a !define as a parameter, but I have to read the value out of an INI-file before. ReadINIStr works only with a user_var.
This is wrong. When you call a dll function, it needs parameters. These parameters can be any string/integer. The DLL doesn't care how the parameter is passed, as long as it gets it. So despite what you think, what you need to do is simply use readinistr, and then use the returned string (in a user var!) as the parameter in your DLL.


As for defines versus variables, you are confused about the difference between compiletime and runtime. I suggest you google it and find out what the difference is.

"Worst case" happened: I tried my code the other day, using the user_var version and it did work. I have no clue, what went wrong before I started this thread. I didn't change anything. :igor:

@MSG: I'm aware of the difference between run- and compiletime. But while playing around with NSIS scripting, in some situations I would prefer the possibility to pass a !define value over to a user_var to use it during compile- and runtime instead of initializing it twice.

At least this possibility would make sense for me - disregarding possible compiling-issues, that I don't know yet. Maybe someone can tell a little bit about what's going on under the hood, while NSIS is compiling...?


When the precompiler finds a reference to a !defined value, in the form of ${DefineName}, it simply replaces the "${DefineName}" text with whatever the define was !defined as. Example:

Precompiler sees (in the nsi script):
!define SomeDefine `bar`
StrCpy $YourVar "foo ${SomeDefine}"

Compiler sees (after precomilation):
StrCpy $YourVar "foo bar"

As you can see, the compiler never even gets to see any defines. The precompiler simply replaces them with their defined text contents. This is why your question about putting defines into variables doesn't make any sense: At runtime, which is when variables are being used, there ARE no defines. There are only strings, and other variables.