Re: problem using netcdf and Borland Delphi


> I am trying to read some cdf data files using Borland Delphi v 5.0 on a
> Windows NT machine.  I downloaded netcdf.dll from the unidata ftp site
>
(ftp://ftp.unidata.ucar.edu/pub/netcdf/contrib/win32/netcdf-3.5-beta5.win32b
> in.ZIP) and put the following definitions in my Delphi code:
>
> function nc_inq_libvers : pchar; external 'netcdf.DLL';
> function nc_strerror (ncerr : integer) : pchar; external 'netcdf.DLL';
> function nc_open (path : pchar; omode : integer; var ncidp : integer) :
> integer; external 'netcdf.DLL';
> function nc_close (ncidp : integer) : integer; external 'netcdf.DLL';
>
> When I call nc_inq_libvers I get what appears (?) to be a reasonable
answer:
>
> 3.5-beta5 of Oct 17 2000 10:28:35 $
>
> but when I call nc_strerror with any integer (I tried a lot of them), I
> always get back

  I think the problem can be in the calling convention and perhaps with the
type of the parameter.

  I have been mixing Delphi with DLLs made in Visual C++, and here is an
examples of external function declaration, perhaps it may help you.

  Delphi Declaration:

function SetValue(Variable: PChar; VariableLength: Cardinal;
                  Value: PChar; ValueLength: Cardinal;
                  var Index, ValueType: Cardinal): Integer; cdecl;
                  external 'Intermed.dll';


  DLL C++ declaration:

#define DllExport extern "C" __declspec( dllexport )

enum TValueType {vtNone=0, vtReal, vtInteger, vtString, vtRealVector};

DllExport int   SetValue(char *Variable, unsigned int VariableLength,
                         char *Value, unsigned int ValueLength, int *Index,
                         TValueType *ValueType);

  As you can see, C++'s ints have been replaced by Delphi's Cardinal, and
the calling convention have been set to "cdecl".

  The only way I know to determine which calling convention you have to use
and which are the types that match C++ (or other languages) types is test
and error (and sometimes a little of inspection of the CPU window).

  By the way, I am very interested in use NetCDF from Delphi in the future,
but now I don´t have the time to do the porting. I'll like very much if you
keep me informed of your progress.

  Of course, if I can help you just write me.

José María González Ondina.

jmg@xxxxxxxxxxxxxx



  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: