Get value of a built-in Windows constant from a string?

Windows specific forum
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Get value of a built-in Windows constant from a string?

Post by BarryG »

Easy question, but maybe hard to answer? How can I do the following:

Code: Select all

Debug "#WM_CLOSE" ; Want: 16
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
User avatar
mk-soft
Always Here
Always Here
Posts: 5402
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Get value of a built-in Windows constant from a string?

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Get value of a built-in Windows constant from a string?

Post 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!
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Get value of a built-in Windows constant from a string?

Post 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.
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Get value of a built-in Windows constant from a string?

Post 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.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Get value of a built-in Windows constant from a string?

Post 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

Code: Select all

Runtime Constants
that makes all constants that the program knows available at runtime. Just an idea.
Post Reply