2016年4月18日月曜日

Fortran DLLをVBAから呼び出す場合の関数名はAliasを利用すべし

背景

Fortranの関数名は,大文字/小文字の区別はされない。

VBAからFortran DLL内の関数(例: testfunction)を呼び出す場合に,VBA側で大文字/小文字を区別しておきたい場合(例: TestFunction)は,
Declare PtrSafe Sub TestFunction Lib "パス~" Alias "testfunction" (引数・・・)

のように宣言すべし。


検証環境

  • OS: Windows 10 Pro(64bit)
  • アプリケーション: Excel 2013(64bit)
  • CPU: Core i7 2.4GHz
  • RAM: 16GB
  • 仮想メモリ: OFF


2 件のコメント:

  1. How did you deal with the interface of Fortran and VBA in Fortran code?
    Such as in Fortran: !DEC$ ATTRIBUTE DLLEXPORT,SRDCALL,ALIAS:"xxx" :: XXX
    and in VBA Private Declare PtrSafe Function xxx Lib "C:\XX\XXX.dll" (ByRef a as double, ByRef b as double).

    返信削除
  2. Sorry for my late reply.



    Fortran source code header

    !DEC$ ATTRIBUTES DLLEXPORT :: xxx



    gfortran compiler command

    gfortran -mrtd -fno-underscoring -shared -o Filename.dll Filename.f90

    Don't care the message "f951.exe: mrtd ignored in 64bit ・・・"



    Excel(64bit) VBA Declaretion

    Declare PtrSafe Sub XXX Lib "C:\xx\Filename.dll" Alias "xxx" (ByRef a As Double, ByRef b As Double)


    Good luck!

    返信削除