News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

IsConstant?

Started by Nordwind64, June 26, 2009, 05:31:03 PM

Previous topic - Next topic

Nordwind64

Hi,

Is it possible to detect, if a system constant is known in a running code?
Just like the function GetProcAdresse for API.

text  db "WM_PAINT",0
;...
invoke IsConstant,addr text
.if eax
;...


Any ideas?
:eek
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

ToutEnMasm

constant can be only loaded in a register or pushed on stack.
at runtime,there is no constant.
Only soluce i see,is to put them in data and to test for equality.
.const
ThisConstant equ 458
.data
Myconst dd ThisConstant
.code
                       mov eax,Myconst
                     .if eax == Text
                         ;do something
                     .endif

ramguru

All those winapi (named) constants are just for developer only, to make things clearer.
None of them are saved into an executable as text labels.
This is really simple to understand, because
WM_PAINT equ 15
it doesn't mean that there can't another constant with the same value.
There could be:
MY_NUMBER equ 15
DIVIDER equ 15
..
So such function simply can't exist :}

edit > But if you mean to detect if constant is defined in include files
& tell that at run time :} wow  .. there is no easy way | unless you wanna make a parser :}

dedndave

most (if not all) of the windows constants or "pins" are located in the windows.inc file

Nordwind64

QuoteAll those winapi (named) constants are just for developer only, to make things clearer.

Yes, I know. The assembler/linker detects the constant-words in code and change them to decimal. If a constant could not find in the include-files, the linker will give an error. Seems, there is no chance to make my idea true...  :(
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

qWord

hi,

it is possible to write a macro, that record the name and value of used Constans. This could look something like (just an idea):

; e.g. inside WndProc
.if uMsg == con(<WM_PAINT>)
.elseif uMsg == con(<WM_CREATE>)
.elseif uMsg == con(<WM_GETTEXT>)
...
.endif


regards, qWord

FPU in a trice: SmplMath
It's that simple!

Nordwind64

Ah, and the macro looks, if the parameter is alpha or numeric? If it is text, the constant was not found in an include. If it is numeric, it was changed... possible?
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

qWord


con macro txt:=<>

IFNDEF const_cntr
const_cntr = 1
@CatStr(<const_name_>,%const_cntr) TEXTEQU <&txt>
@CatStr(<const_value_>,%const_cntr) = txt
EXITM <&txt>
ENDIF

cc_flag = 0
cc_cntr = 1

REPEAT const_cntr
% IFIDN <&txt>,<@CatStr(<const_name_>,%cc_cntr)>
cc_flag = 1
EXITM
ENDIF
cc_cntr = cc_cntr + 1
ENDM

IF cc_flag EQ 0
const_cntr = const_cntr + 1
@CatStr(<const_name_>,%const_cntr) TEXTEQU <&txt>
@CatStr(<const_value_>,%const_cntr) = txt
ENDIF

EXITM <&txt>
endm

; this macro can be changed, so that it creates
; a (string-)table in data-section -> you can read this table at runtime
show_con macro
IFNDEF const_cntr
%echo no const used
EXITM
ENDIF

%echo Used Const's:

pushcontext radix
.radix 16
cc_cntr = 1
REPEAT const_cntr
%echo  @CatStr(<const_name_>,%cc_cntr) EQU @CatStr(<0>,%(@CatStr(<const_value_>,%cc_cntr)),<h>)
cc_cntr = cc_cntr + 1
ENDM
popcontext radix
endm

;-------------------------------

; e.g. inside WndProc
.if uMsg == con(<WM_PAINT>)
.elseif uMsg == con(<WM_CREATE>)
.elseif uMsg == con(<WM_GETTEXT>)
.endif

; show used EQU's in build-consol
show_con
FPU in a trice: SmplMath
It's that simple!

Nordwind64

Thank you! But I'm not interested in building a constant-database.  :P
The macro only must detect, if the parameter is alpha or numeric. Unfortunately, I do not feel well to write macros. Can you please help again?
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

Nordwind64

Seems, it don't work.

iscon MACRO arg
  % echo arg
ENDM

iscon WM_PAINT


Gives back:

WM_PAINT

Not 15...

:'(
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

qWord

OK, did i understand you right:

IsCon(12345)   ; this should return FALSE
IsCon(WM_PAINT); this should return TRUE


FPU in a trice: SmplMath
It's that simple!

Nordwind64

This.

IsCon(WM_DON_T_EXISTS)   ; this should return FALSE
IsCon(WM_PAINT); this should return TRUE
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

Nordwind64

Quote from: Nordwind64 on June 26, 2009, 08:20:24 PM
This.

IsCon(WM_DON_T_EXISTS)   ; this should return FALSE
IsCon(WM_PAINT); this should return TRUE


But it will not work. MASM don't translate the WM_PAINT to decimal as I though...
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

qWord

You want to proof, if an Constant is defined? If so, use IFNDEF/IFDEF ...

IsCon macro txt:=<>
IFNDEF txt
EXITM <FALSE>
ELSE
EXITM <TRUE>
EXITM
endm


or you want the number as literal?:

@CatStr(%(WM_PAINT)) ; this returns "15"
FPU in a trice: SmplMath
It's that simple!

Nordwind64

I would like to know whether the constant is known in the programme or not. WM_PAINT should be confessed. WM_SOMETHING not.
Excuse my bad English...
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink