在 Delphi 应用程序中使用 HDF5 dll

用户3384674

我想在我的 Delphi 10.2 Windows 10 64 位应用程序中使用 HDF5 ( https://www.hdfgroup.org/ )。

我使用带有以下声明的 hdf5.dll(用 C 编写):

const
  H5P_DEFAULT: Integer = 0;

  H5F_ACC_RDONLY: Integer = $0000;  //*absence of rdwr => rd-only */
  H5F_ACC_RDWR: Integer = $0001;    //*open for read and write    */
  H5F_ACC_TRUNC: Integer = $0002;   //*overwrite existing files   */
  H5F_ACC_EXCL: Integer = $0004;    //*fail if file already exists*/
  H5F_ACC_DEBUG: Integer = $0008;   //*print debug info      */
  H5F_ACC_CREAT: Integer = $0010;   //*create non-existing files  */

type
  hid_t = Integer;
  hsize_t = UINT64;
  hssize_t = INT64;
  size_t = Cardinal;
  herr_t = Integer;
  unsigned = Cardinal;

  H5_ih_info_t = record
   index_size: hsize_t;
   heap_size: hsize_t;
  end;

  Tsohm =record
    hdr_size: hsize_t;
    msgs_info: H5_ih_info_t;
  end;

  TH5F_info_t = record
    super_ext_size: hsize_t;
    sohm: Tsohm;
  end;
  PH5F_info_t= ^TH5F_info_t;

//initializes the HDF5 library
function H5open: herr_t; cdecl; external 'hdf5.dll';

//flushes all data to disk, closes all open HDF5 objects, and cleans up all memory used by the HDF5 library
function H5close: herr_t; cdecl; external 'hdf5.dll';

//retrieves the major, minor, and release numbers of the version of the HDF5 library
function H5get_libversion( var majnum: unsigned; var minnum: unsigned; var relnum:unsigned): herr_t;  cdecl; external 'hdf5.dll';

// Opens an existing HDF5 file.
function H5Fopen(filename: PAnsiChar; flags: unsigned; fapl_id: hid_t): hid_t; cdecl; external 'hdf5.dll';

//Terminates access to an HDF5 file.
function H5Fclose(file_id: hid_t): herr_t; cdecl; external 'hdf5.dll';

//Returns global information for a file
function H5Fget_info2(obj_id: hid_t; file_info: PH5F_info_t): herr_t; cdecl; external 'hdf5.dll';

//Creates a new simple dataspace and opens it for access.
function H5Screate_simple(rank: Integer; current_dims: Pointer; maximum_dims: Pointer): hid_t; cdecl; external 'hdf5.dll';

//Creates a new group and links it into the file.
function H5Gcreate2(loc_id: hid_t; aname: PAnsiChar;  lcpl_id: hid_t; gcpl_id: hid_t; gapl_id: hid_t): hid_t; cdecl;  external 'hdf5.dll';

以下代码

procedure TForm1.Button1Click(Sender: TObject);
var
  status: herr_t;
  majnum, minnum, relnum: unsigned;
  file_id: hid_t;
  group_id: hid_t;
  dataspace_id: hid_t;
  dataset_id: hid_t;
  dims: array[0..1] of hsize_t;
  file_info: TH5F_info_t;
  pfile_info: PH5F_info_t;
begin
  status := H5open;
  Memo1.Lines.Add('H5open ' + IntToStr(status)); //status=0 -> OK

  status := H5get_libversion(majnum, minnum, relnum);
  Memo1.Lines.Add('H5get_libversion ' + IntToStr(status)); //status=0 -> OK
  Memo1.Lines.Add(IntToStr(majnum)); //majnum=1
  Memo1.Lines.Add(IntToStr(minnum)); //minnum=10
  Memo1.Lines.Add(IntToStr(relnum)); //relnum=6
                                     //-> version 1.10.6.

  file_id := H5Fopen('example.h5', H5F_ACC_RDWR, H5P_DEFAULT);
  Memo1.Lines.Add('H5Fopen ' + IntToStr(file_id));  //file_id=0 ->

  pfile_info:[email protected]_info;
  status:=H5Fget_info2(0, pfile_info);
  Memo1.Lines.Add('H5Fget_info2 ' + IntToStr(status)); //status=-1 -> ERROR

  group_id:=H5Gcreate2(file_id, 'testgroup', H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  Memo1.Lines.Add('H5Gcreate2 ' + IntToStr(group_id)); //group_id=-1 -> ERROR

  dims[0]:=4;
  dims[1]:=6;

  dataspace_id := H5Screate_simple(2, @dims, nil);
  Memo1.Lines.Add('H5Screate_simple ' + IntToStr(dataspace_id)); //dataspace_id=2 -> OK

  status:=H5Fclose(file_id);
  Memo1.Lines.Add('H5Fclose ' + IntToStr(status)); //status=-1 -> ERROR

  status:=H5close;
  Memo1.Lines.Add('H5close ' + IntToStr(status)); //status=0 -> OK
end;

给出这个输出

H5open 0
H5get_libversion 0
1
10
6
H5Fopen 0
H5Fget_info2 -1
H5Gcreate2 -1
H5Screate_simple 2
H5Fclose -1
H5close 0

H5Fopen 似乎可以工作,但之后使用 file_id 的所有函数都返回 -1,这意味着发生了错误。

可能是什么问题呢?

用户3384674

Dave Nottage 的评论就是答案。类型不正确。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章