Author Topic: Best way to define WinApi constants?  (Read 1853 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Hero Member
  • *****
  • Posts: 872
Best way to define WinApi constants?
« on: April 19, 2016, 12:38:54 AM »
Hi Charles,

What would be the best way to define WinApi constants in OxygenBasic: const, % or #define?

For experimenting with the BCX runtime library I use decimal values for the WinApi constants. My assumption was that it would be easier for me to find the values of the referring messages. But I am not sure any more. Would it be better to use hexadecimal values instead?

Roland

Code: OxygenBasic
  1. #include "$/inc/console.inc"
  2.  
  3. const aText = "aText"  
  4. % bText = "bText"    
  5. #define cText "cText"
  6.  
  7. printl "aText: illegal" 'aText
  8. printl "bText: " bText
  9. printl "cText: " cText
  10. printl ""
  11.  
  12. const aConst = -45
  13. % bConst = -45
  14. #define cConst -45
  15.  
  16. printl "aConst: " aConst
  17. printl "bConst: " bConst
  18. printl "cConst: " cConst
  19. printl ""
  20.  
  21. const aConstant = (-45)
  22. % bConstant = (-45)
  23. #define cConstant (-45)
  24.  
  25. printl "aConstant: " aConstant
  26. printl "bConstant: " bConstant
  27. printl "cConstant: " cConstant
  28.  printl ""
  29.  
  30. printl "Enter ..." : waitkey
  31.  

Output:
aText: illegal
bText: bText
cText: cText

aConst: -45
bConst: 45
cConst: 45

aConstant: -45
bConstant: -45
cConstant: -45

Enter ...

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4205
    • Oxygen Basic
Re: Best way to define WinApi constants?
« Reply #1 on: April 19, 2016, 12:47:41 PM »
Hi Roland,

I never use const, and I see it requires further attention.

% is most convenient for equates, but you can also use #define within c-style headers.

If the equates have bitwise flags, window styles for example, then it is preferable to express them in hexadecimal.

Arnold

  • Hero Member
  • *****
  • Posts: 872
Re: Best way to define WinApi constants?
« Reply #2 on: April 20, 2016, 12:20:37 AM »
Hi Charles,

thank you again. Until now I did not realize that bitwise flags could be embedded in the equates. I only wondered why some messages did not fire in some cases. I will rework my constants file. It was used in a very old project in another language and it needs a revision anyway.

Roland

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4205
    • Oxygen Basic
Re: Best way to define WinApi constants?
« Reply #3 on: April 22, 2016, 12:54:59 AM »
const is more like dim:

const float a=4.5
const string s="text"



but the type defaults to sys, so this is also allowed:

const x=45