Byte PTR

This forum is meant for questions and discussions about the X# language and tools
Post Reply
stefan.ungemach
Posts: 71
Joined: Thu Jul 15, 2021 10:46 am
Location: Germany

Byte PTR

Post 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?
ic2
Posts: 1865
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Byte PTR

Post 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
User avatar
robert
Posts: 4567
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Byte PTR

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
stefan.ungemach
Posts: 71
Joined: Thu Jul 15, 2021 10:46 am
Location: Germany

Byte PTR

Post 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 :)
Post Reply