Page 1 of 1
Get value of a built-in Windows constant from a string?
Posted: Sun Jan 30, 2022 2:35 am
by BarryG
Easy question, but maybe hard to answer? How can I do the following:
In other words, get the built-in Windows constant value from the string, without having to declare/define them all (since the Win32 API has thousands).
Reason for asking: the user will be specifying a Windows constant to use for SendMessage, so I need to know its value to send.
But really I'd like to get ANY Windows constant value, and not just the ones prefixed with "#WM_" for window messaging.
I looked at the Runtime library but it doesn't work:
Code: Select all
Debug #WM_CLOSE ; 16
Debug GetRuntimeInteger("#WM_CLOSE") ; Want 16 but returns 0
Re: Get value of a built-in Windows constant from a string?
Posted: Sun Jan 30, 2022 12:58 pm
by mk-soft
This will not work at runtime.
But you can export all constants from the pbcompiler beforehand and store them in an SQLite database, for example.
Link:
https://www.purebasic.fr/english/viewtopic.php?t=63839
Re: Get value of a built-in Windows constant from a string?
Posted: Sun Jan 30, 2022 10:16 pm
by BarryG
Thanks, but there's too many constants to include with my app (13798!), plus with each new Windows update there will be even more, so having a static pre-made list isn't an option because it will become out of date very quickly. Oh well, looks like there's no runtime way to get them on demand, so I'll just ditch this idea.
BTW, my search led to this topic ->
https://reverseengineering.stackexchang ... efinitions
Which in turn led to this awesome site (The Magic Number Database) ->
https://www.magnumdb.com/
So at least it wasn't a lost cause because the MNDB is a fantastic resource to bookmark!
Re: Get value of a built-in Windows constant from a string?
Posted: Sun Jan 30, 2022 10:44 pm
by Little John
BarryG wrote:
I looked at the Runtime library but it doesn't work:
Code: Select all
Debug #WM_CLOSE ; 16
Debug GetRuntimeInteger("#WM_CLOSE") ; Want 16 but returns 0
For the record: Using it according to the documentation
does work.
Code: Select all
Runtime #WM_CLOSE
Debug GetRuntimeInteger("#WM_CLOSE")
However, unfortunately this will probably not solve your problem.
Re: Get value of a built-in Windows constant from a string?
Posted: Sun Jan 30, 2022 10:47 pm
by BarryG
Thanks, Little John! But yeah, as you noted, I can't really have 13798 "Runtime" lines in my app to cover all constants.
Just wondering: is "Winuser.h" saved somewhere in the Windows folder, for parsing? That would work, but I can't find it.
Re: Get value of a built-in Windows constant from a string?
Posted: Sun Jan 30, 2022 10:59 pm
by Little John
Technically speaking, it doesn't seem to be necessary to mention each constant separately, in order to make it available at runtime (see
Runtime Enumeration). Maybe Fred could extend the Runtime capabilities of PureBasic, so that we'd have a new command say
that makes all constants that the program knows available at runtime. Just an idea.