Try something like this, if you want a single string (not tested):

int byteLength = Marshal.SizeOf(Of IntPtr);
IntPtr intPtr = Marshal.AllocHGlobal(byteLength);

H5A.read(attributeId, attributeTypeId, intPtr);

string result = Marshal.PtrToStringAnsi(intPtr);

If you want a more general way to read multiple strings at once, the code must 
be modified slightly.

Best regards,
Vincent

Von: Hdf-forum [mailto:hdf-forum-boun...@lists.hdfgroup.org] Im Auftrag von 
Gerd Heber
Gesendet: Donnerstag, 30. März 2017 16:58
An: HDF Users Discussion List <hdf-forum@lists.hdfgroup.org>
Betreff: Re: [Hdf-forum] Reading VLEN string attribute values.

What’s the storage layout of the attribute?
(i.e., is it H5S_SIMPLE or H5S_SCALAR?)

G.

From: Hdf-forum [mailto:hdf-forum-boun...@lists.hdfgroup.org] On Behalf Of Matt 
Wood
Sent: Thursday, March 30, 2017 9:42 AM
To: hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>
Subject: [Hdf-forum] Reading VLEN string attribute values.

Hi,

I am using HDF.PInvoke 1.10.0.4 but I am struggling to read the string value of 
an attribute when it is variable length.

Ultimately I believe I need to call:

GCHandle hnd = GCHandle.Alloc(data, GCHandleType.Pinned);
int err = H5A.read(aid, typeId, hnd.AddrOfPinnedObject());
hnd.Free();

Where data is a suitable object.

I am confident that the attribute id (aid) is correct because it works for all 
the other attributes types.

I am not so confident on the typeId, I have tried:

   H5T.get_type(aid);
* H5T.get_native_type(tid);
   H5T.create(H5T.class_t.VLEN, H5T.VARIABLE);
   H5T.create(H5T.class_t.STRING, H5T.VARIABLE);

Likewise for the data and I have tried:

*  data = new byte[256];
    data = new IntPtr[1]; => data[0] = GCHandle.Alloc(byte[256], 
GCHandleType.Pinned).AddrOfPinnedObject()

The only time some non-zero values were returned was case (*) but then I 
couldn't relate the values to the expected text.

Thanks,

Matt
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Reply via email to