Page 1 of 1

A pointer to a constant

Posted: Fri Jun 07, 2013 5:44 pm
by User_Russian
It would be great if one could get a pointer to a constant what is required for some API functions.

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 6:00 pm
by Fred
A pointer to constant makes no sens, which API needs that ?

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 6:12 pm
by User_Russian

Code: Select all

#ClassName = "MyWin"

wc.WNDCLASSEX 
wc\cbsize        = SizeOf(WNDCLASSEX) 
wc\hInstance     = hInstance
wc\lpfnWndProc   = 0
wc\hCursor       = LoadCursor_(0, #IDC_ARROW) 
wc\hbrBackground = #COLOR_WINDOW
wc\lpszClassName = #ClassName ; It requires a pointer!
RegisterClassEx_(@wc)

hWnd  = CreateWindowEx_(0, #ClassName, #ClassName, #WS_VISIBLE, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, 0, 0, 0, 0)

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 6:17 pm
by ts-soft
The structure require a pointer to a string, but not to a constant!
http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 6:20 pm
by skywalk
I remember stumbling on this once or twice:
I had problems passing pointers to literal constants: @3.14 or @"mystring".
Instead, I created a variable and assigned it to my constant and then passed a pointer to my variable.

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 6:26 pm
by User_Russian
In the constant string is stored. Right?
When the executable file is loaded into memory, all the constants be kept in memory, and why not get a pointer to this memory?

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 6:33 pm
by ts-soft
User_Russian wrote:When the executable file is loaded into memory, all the constants be kept in memory, and why not get a pointer to this memory?
No constant in memory, all use of constants replaced with value. Constants not available in executable!

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 6:40 pm
by Fred
What you are refering is a C macro, not a constant (there is no real constant in C).

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 7:00 pm
by User_Russian
ts-soft, constant is loaded into memory, otherwise DataSection not exist.
A pointer to a constant can be obtained.
Otherwise, as you explained to this code works?

Code: Select all

#Const = "Test"

*Point=0
!MOV dword [p_Point],_S1

Debug *Point
Debug PeekS(*Point) 

x.s=#Const
And it is really a pointer to a constant and its value can be changed.

Code: Select all

#Const = "Test"

*Point=0
!MOV dword [p_Point],_S2

Debug *Point
Debug PeekS(*Point) 

PokeS(*Point, "1234")

x.s=#Const

Debug x

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 7:06 pm
by Fred
It's not true for numeric constants for example

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 7:09 pm
by User_Russian
I mean the only string constants.

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 7:15 pm
by ts-soft
A literal string or constant string is in datasection. The constant in executable is replaced by pointer to the string, but the constant itself is no more available!

Re: A pointer to a constant

Posted: Fri Jun 07, 2013 8:41 pm
by Shield
Receiving a pointer to a string constant does make sense.
However, Fred's points are valid too.

I could imagine that PB combines constants (literal or #const) with the same value
into one single entry in the data section of the executable, so receiving a pointer
to that location makes perfect sense and is a valid reason for a feature request.

Re: A pointer to a constant

Posted: Sat Jul 27, 2013 2:52 pm
by skywalk
Macro can't find the string pointer address :(

Code: Select all

#someconst$ = "Hello to you!"
Macro StrCmp(str1, str2, UseCase=#PB_String_NoCase)
  Bool(CompareMemoryString(@str1, @str2, UseCase) = #PB_String_Equal) ;<-- Syntax Error in Macro @#Somestring$
EndMacro
s2$ = "hello World!"
Debug StrCmp(#SomeConst$,s2$)  ; ,#PB_String_CaseSensitive)