gfortran, DLL, underscore

前端 未结 4 1474
我在风中等你
我在风中等你 2021-01-25 14:35

I want to access some subroutines from a third party DLL. The functions use STDCALL as the calling convention.

Running dumpbin /export foo.dll gives me some

4条回答
  •  盖世英雄少女心
    2021-01-25 15:21

    A different approach is to use the ISO C Binding of Fortran 2003, which is supported by gfortran >= 4.3. This will automatically use the underscoring conventions of C (i.e., probably none), rather those of the Fortran compiler. It will also give you control over the case (capitalization) of the subroutine names, if the Windows linker cares about that. Fortran is case insensitive, and so you can call Fortran subroutines by any case -- probably the linker is converting to lower case.

    Including the following "interface" in the declarations of the Fortran routine that calls "Foo" describes Foo to be a C subroutine (void function) with a single argument of double type -- Fortran input/output, or a pointer in C. If Foo has other properties, the interface needs to be changed. The "bind" clause specifies the case-sensitive name to provide to the linker. If you call Foo from several Fortran routines, then it is best to put the interface into a module and "use" it from each Fortran routine.

    This is intended for C -- maybe it will work for Visual Basic. The ISO C Binding gives a lot of control, so if this doesn't work, maybe some variation will.

    interface VisBasSubs
    
       subroutine foo (DoubleArg)  bind (C, name="Foo")
    
          use iso_c_binding, only: c_double
          real (kind=c_double), intent (inout) :: DoubleArg      
    
       end subroutine foo
    
    end interface VisBasSubs
    

提交回复
热议问题