Calling the NAG Library from Microsoft Visual Basic .NET

The information here relates to calling the NAG Library FL Interfaces.

Many of the Library routines are callable from Visual Basic .NET (VB.NET). To assist you with the mapping between the Fortran-based FL Interface and VB.NET types, zip files containing a VB.NET header file (flvbdnet64.vb for use with 64-bit Libraries or flvbdnet.vb for use with 32-bit Libraries) are provided. If you wish to use a NAG Library routine, it is recommended that you copy and paste the relevant sections of the appropriate file into your VB.NET application.

Examples of the use of the DLLs from VB.NET may also be downloaded: 64-bit examples or 32-bit examples.

Key information:

  • The Declare statements for use with VB.NET are provided in the file flvbdnet64.vb for 64-bit applications (flvbdnet.vb for 32-bit applications).
  • To use the version of the DLL based on MKL BLAS/LAPACK, change the DLL name in the declarations from "NLW6Ixxxx_nag.dll" to "NLW6Ixxxx_mkl.dll" for 64-bit applications (change "NLW32xxxx_nag.dll" to "NLW32xxxx_mkl.dll" for 32-bit applications).
  • Use the Declare statements provided either by copying from the file and pasting them into your module or by importing the file into your VB.NET project as a module.
  • Fortran arrays start at 1, VB.NET arrays start at 0.
  • The following type of mappings are used. Integer corresponds to Fortran's INTEGER type, Double to Fortran's DOUBLE PRECISION and Single to Fortran's REAL.
  • Integer is used for Fortran's LOGICAL; NAGTRUE and NAGFALSE are Integer constants defined as -1 and 0 respectively.
  • The structures Complex and ComplexSimple correspond to Fortran's COMPLEX*16 and COMPLEX respectively.
  • All scalar values must be passed by reference (ByRef). By default, VB.NET passes by value (ByVal), so this must be specified explicitly. For clarity, ByRef and ByVal are used explicitly throughout the Declare statements.
  • Where an array argument is required, the name of the array is passed. All arrays are passed by value. (Within the declaration they have one of the following decorations: <[In]()>, <Out()> or <[In](),Out()> depending on the Fortran usage.) See the G02EEFE() Sub procedure within the various_routines_64 (64-bit) or various_routines (32-bit) example.
  • In VB.NET, arrays in callback functions are represented by IntPtrs passed by value. See the d02ejf_example code (32-bit only).
  • IntPtrs passed by reference are used for the Fortran c_ptr type. See the E04JDFE() Sub procedure within the various_routines_64 (64-bit) or various_routines (32-bit) example.
  • VB.NET arrays are row ordered, not column ordered as in Fortran. This means that arrays will need to be transposed for correct interpretation by a Fortran routine.
  • Because of the different array storage, the "leading dimension" of a Fortran array will be the second dimension of the corresponding VB.NET array. For example, A(2,3) in VB.NET would pass 4 as the "leading dimension", noting that this is because arrays start from index 0.
  • String handling is different for 64-bit and 32-bit programs.

    For 64-bit applications:

    • When the Fortran expects a scalar argument of type CHARACTER* (e.g. CHARACTER*(*) or CHARACTER*1), the actual VB.NET argument is a String, passed by value. The length of this string must be passed by value as an Integer at the end of the argument list.
    • When the Fortran expects an array argument of type CHARACTER*, the actual VB.NET argument is a single String in which all the array elements are concatenated. The length of one element of the array must be passed by value as an Integer at the end of the argument list. See the M01CCFE() Sub procedure within the various_routines_64 example.

    For 32-bit applications:

    • When the Fortran expects a scalar argument of type CHARACTER* (e.g. CHARACTER*(*) or CHARACTER*1), the actual VB.NET argument is a String, passed by value. The length of this string must be passed by value as an Integer immediately after the String argument.
    • When the Fortran expects an array argument of type CHARACTER*, the actual VB.NET argument is a single String in which all the array elements are concatenated. The length of one element of the array must be passed by value as an Integer immediately after the String argument. See the M01CCFE() Sub procedure within the various_routines example.
  • When the Fortran expects a callback function as an argument, an interface must be declared on the VB.NET side by defining a Delegate function; the routine argument is passed by value as being of the type of this Delegate function. When calling the Fortran routine from VB.NET, the function implementing the Delegate interface will be passed as an argument using the keyword AddressOf. See the d01bdf_example code (32-bit only) or the D01BDFE() Sub procedure within the various_routines_64 or various_routines example.
  • For these declarations to be recognised by VB.NET, the following line is needed at the top of the VB.NET source code:
     Imports System.Runtime.InteropServices
    	
  • If using the 32-bit NAG Library DLLs on a 64-bit system, it may be necessary to set the Target CPU to x86 to avoid a BadImageFormatException.