How to pass a char array from Fortran to EXCEL VBA?
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)
id = 2
Call NPTEST(id, AddressOf funtest)
and here is the VBA function called by the fortran dll:
Sub funtest(mode As Long, ptr As Variant)
mode = mode + 1
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?