Archive: Problem with !define


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

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


${_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.

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

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

kike_velez and Afrow UK thanks.


If you're trying to pass HKLM for all users and HKCU for current user, see SHCTX in the latest CVS version.


Is it possible in future to change all root_key (HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD) at runtime?


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.