` Printed Icetips Article

Icetips Article



Windows API: Assigning address to reference
2006-02-19 -- Jim Kane
 
> Hi all.  I have an address of a cstring in a ULONG variable.  How can I
> make a &CSTRING reference point at that address?
>
> I can't do cstrref &= myulong because the type doesn't match.  I'd use
> cstrref &= address(myulong) but that's not right.  I tried doing
> tmpulongRef &= mylong; cstrref &= address(tmpulongRef) but that doesn't do
> it either.

Check the help for reference variables. It will clearly tell you can't.
Also note the use of ( ) to force a cast and avoid type problems.

cref &= (myulong)

Will point at it but the size will be considered zero which will screw
things up for some commands where the runtime needs the cstring size and
work just fine for other things.

If you want to rely on the undocumented inner workings of c string ref
variables you can do what you want to.

Usually a bad idea when there are api c string functions to manipulate
cstring.

Here's enough rope to hang yourself - code will break if SV changes the
internal structure of a cstring ref variable.

Jim kane

program
  map
  end
crefGroup group,pre()
cRef &cstring
  end
crefgroupOver group, over(crefgroup)
Theaddress long
thesize long
  end
cVar cstring(200)
myulong ulong
sizeofcstring long
  code
 !a cstring to test with
  cVar = 'cref Test'

  !make the ref variable point to cVar
  myulong = address( cVar )
  sizeOfcstring = size( cvar)  crefgroupover.theaddress = myulong
  crefgroupover.thesize = sizeofcstring

 !see if it worked
  message( cref )
 return



Printed May 2, 2024, 3:27 am
This article has been viewed/printed 35116 times.