- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Hi
I am making a fortran dll that I can call from EXCEL VBA and I also need to have the fortran dll to call another function defined in VBA. This function to be called from Fortran must have an argument that is a char array.Here is what I am trying to do:
VBA code to call a fortran subroutine defined in dll:
Declare PtrSafe Sub NPTEST Lib "D:\SNOPT\SNOPTDLL\SNOPTDLL\Release\SNOPTDLL.dll" Alias "_NPTEST@8" (id As Long, ByVal confun As Long)
Sub testtest()
Dim id
id = 2
Call NPTEST(id, AddressOf funtest)
End Sub
Here is the fortran subroutine:
subroutine nptest(id, confun)
!DEC$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE :: NPTEST
!DEC$ ATTRIBUTES ALIAS:"_NPTEST@8" :: NPTEST
!DEC$ ATTRIBUTES REFERENCE :: id
!DEC$ ATTRIBUTES REFERENCE :: confun
implicit double precision (a-h,o-z)
external confun
character*8 cw(50)
mode = id
.....
call confun(mode, cw)
call confun(mode, cw)
call confun(mode, cw)
call confun(mode, cw)
return
end subroutine
and here is the VBA function called by the fortran dll:
Sub funtest(mode As Long, ptr As Variant)
MsgBox mode
mode = mode + 1
End Sub
As you can see I need to pass a pointer to the char array cw to the VBA function but I am not sure what data type I should use for ptr in the VBA function. I tried many types and EXCEL always crashes after the last function call (It is called 4 times from Fortran). if cw is double array I have no problem and everything works, but as soon as I change cw to char array it crashes. Any suggestions?
コピーされたリンク
