- NSIS Discussion
- Problem with !define
Archive: Problem with !define
Instructor
27th February 2005 18:58 UTC
Problem with !define
Is there any way to pass this code?
Name "RegSearch"
OutFile "RegSearch.exe"
!macro RegSearch _ROOTKEY
!define _ROOT ${_ROOTKEY}
Call RegSearch
!macroend
Function RegSearch
EnumRegKey $0 ${_ROOT} "" 1
FunctionEnd
Section
!insertmacro RegSearch HKLM
MessageBox MB_OK "$0"
SectionEnd
Afrow UK
28th February 2005 12:02 UTC
Are you saying that ${_ROOT} has no value in the RegSearch function call?
Edit: Oh I see. Just use Push ${_ROOTKEY} and in your Function Pop it into a variable.
-Stu
Instructor
28th February 2005 15:25 UTC
${_ROOT} can't be a variable
It seems like functions compiles first and then macros and sections.
I see only one solution, but it's not comfortably for the user:
Function RegSearch
!define _ROOT HKLM
EnumRegKey $0 ${_ROOT} "" 1
FunctionEnd
May be there is another way.
Afrow UK
28th February 2005 16:22 UTC
The only suggestion that I can think of, is that you have multiple copies of the RegSearch functions with different names (i.e. RegSearch_HKLM) which is called like so:
!macro RegSearch _ROOTKEY
Call RegSearch_${_ROOTKEY}
!macroend
You are right that the function is only compiled once, therefore you cannot change the value of ${_ROOT}.
-Stu
kike_velez
1st March 2005 09:24 UTC
What´s about a change the order :)
This compile for me:
Name "RegSearch"
OutFile "RegSearch.exe"
!macro RegSearch _ROOTKEY
!define _ROOT ${_ROOTKEY}
Call RegSearch
!macroend
Section
!insertmacro RegSearch HKLM
MessageBox MB_OK "$0"
SectionEnd
Function RegSearch
EnumRegKey $0 ${_ROOT} "" 1
FunctionEnd
Best Regards
Instructor
1st March 2005 10:48 UTC
kike_velez and Afrow UK thanks.
kichik
1st March 2005 18:48 UTC
If you're trying to pass HKLM for all users and HKCU for current user, see SHCTX in the latest CVS version.
Instructor
23rd March 2005 10:42 UTC
Is it possible in future to change all root_key (HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD) at runtime?
kichik
24th March 2005 15:48 UTC
I doubt it. It'll break backwards compatibility because it'll be converted into defines. You can submit a feature request, if one doesn't already exist, to keep the request from fading away in the forum.