xsharp.eu • Byte PTR
Page 1 of 1

Byte PTR

Posted: Mon May 08, 2023 2:58 pm
by stefan.ungemach
Hi all,

I have some code to be migrated from VO to X# which simulates kind of a low-level wildseek with ADS functionality.

There is a variable

LOCAL pR as Byte PTR

which is at some point calculated from another pointer (it all comes down to do something with DBF headers):

pRecBuf := memAlloc(dwBufSize + 5)
pR := pRecBuf + 4

Later this goes into a function like this

ACE.ADSGetRecord(hTbl, pR, pRS)

where the function now does expect a BYTE[] for pR - so the compiler throws an error XS1503. Can someone please point me in the right direction how to deal with pR so that all the pointer arithmetics still work?

Byte PTR

Posted: Mon May 08, 2023 3:19 pm
by ic2
Hello Stefan,

Looking at Meinhards reply in a comparable case (https://www.xsharp.eu/forum/public-vo-v ... type#20466) I'd say this could work:(not tested & not sure if it actually does with BYTE[]) but you could quickly give it a try:

Code: Select all

BYTE[](_CAST, pR)
Dick

Byte PTR

Posted: Mon May 08, 2023 3:25 pm
by robert
Stefan,
This is difficult without seeing what you are doing with the pR.
And what are you doing with the first 4 bytes?

To allocale the byte array you could use

pBytes := Byte[]{ (INT) dwBuffSize)

If you want to keep using the ptr, you can allocate the byre array and then use Marshal.Copy() to copy the bytes to the pointer.
Robert

Byte PTR

Posted: Wed May 17, 2023 9:49 am
by stefan.ungemach
Dick, Robert,

thanks, but both examples don't even compile (the Parser throws XS9002 unexpected input ')').

What finally compiles is this (based on Roberts suggestion):

pBytes := BYTE[]{dwBufSize}
ACE.ADSGetRecord(hTbl, pBytes, @dwBufSize)
System.Runtime.InteropServices.Marshal.Copy( pBytes, 0, pR, dwBufSize )

I hope this what was meant :)