Ptr value

Is it possible to know the value of a Ptr?
According to LR a Ptr is “A 4-byte pointer to a chunk of memory.”
I’ve tried:

Dim v as Integer =  Ctype(ptr, Integer)

but it doesnt work,

maybe you can put it in a memoryblock and read as integer.

A simple way
v= ptr.int32Value(0)
This gives access to the integer value stored at the pointer address
May be help

Ramon, do you need the integer the ptr points to?
Or the number of the address the ptr points to?

Two different things.

Thanks Franois. It works. Well almost, in fact V = ptr.int32(0) is enough.
Thanks Christian. I thought I needed the value, but you are right: I need the address value.

OK Ramon
Xojo is really adapted for pointer use: when you know the address of the pointer you can get back everything located at the address by using an offset which moves the pointer to the required value. This can be also done for structures.
Regards

What is that you’re trying to do?

Also it’s worth noting that on 64-Bit a Ptr is 8-bytes.

Double check and make sure that the value stored at the location is actually a int32, quite often it’s a integer and when you compile for 64-Bit you’ll get the wrong result. Also watch out for a Int32 and Uint32, two different results.

@Sam : You’re right value depends on 32-or 64 bit. This is just a suggestion how to access data pointed by Ptr or MemoryBlock.
Here is an example to access OpenCV IplImage values (32-bit version) via a pointed structure

// ipl is a Ptr to an opecv Image
//MemoryBlock can also used
dim opencvImage as IplImage
opencvImage.nSize=ipl.int32(0)
opencvImage.ID=ipl.int32(4)
opencvImage.nChannels=ipl.Int32(8)
opencvImage.alphaChannel=ipl.int32(12)
opencvImage.depth=ipl.int32(16)
opencvImage.colorModel=chr(ipl.int8(20)) + chr(ipl.int8(21)) + chr(ipl.int8(22)) + chr(ipl.int8(23))
opencvImage.channelSeq=chr(ipl.int8(24)) + chr(ipl.int8(25)) + chr(ipl.int8(26)) + chr(ipl.int8(27))
opencvImage.dataOrder=ipl.int32(28)
opencvImage.origin=ipl.int32(32)
opencvImage.align=ipl.int32(36)
opencvImage.width=ipl.int32(40)
opencvImage.height=ipl.int32(44)
opencvImage.roi=Ipl.Ptr(48)
opencvImage.maskRoi=ipl.ptr(52)
opencvImage.imageId=ipl.ptr(56)
opencvImage.tileInfo=ipl.ptr(60)
opencvImage.imageSize=ipl.Int32(64)
opencvImage.imageData=ipl.ptr(68)
opencvImage.widthStep=ipl.Int32(72)
opencvImage.bm0=ipl.Int32(76)
opencvImage.bm1=ipl.int32(80)
opencvImage.bm2=ipl.int32(84)
opencvImage.bm3=ipl.int32(88)
opencvImage.cm0=ipl.int32(92)
opencvImage.cm1=ipl.int32(96)
opencvImage.cm2=ipl.int32(100)
opencvImage.cm3=ipl.int32(104)
opencvImage.imageDataOrigin=ipl.Ptr(108)
return opencvimage

Best regards

It looks like you’re populating a Structure, if that’s the case, as long as the datatype as correct you should be able to use “ptr.IplImage”

I looked at what I could online and it does indicate that most of the properties are UInt32.
https://github.com/se-research/OpenDaVINCI/blob/master/libodsimulation/include/core/wrapper/OpenCV/OpenCVImage.h

Unit32s are not the same Int32s.
http://documentation.xojo.com/index.php/UInt32

But then again, I would double check against the header files of the OpenCV library that you’re actually linking against.

Just in case.

Hi Sam
I’ve tested 64-bit access to OpenCV with Xojo : apparently some problem for integer and int32 since some functions are OK and some other fail. I’ll try to test further ASAP.
Thanks for your suggestions

You’re welcome.

The biggest problem is using the wrong datatype, under 32-Bit many Integer types are identical, however under 64-Bit they’re not. Don’t worry, I’ve made the same mistake and so have many others. 64-Bit forces you to use the right integer type.