Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29541 Discussions

Problem with multiple string variables returning to EXCEL VBA

jlgilber
Beginner
627 Views

I have downloaded V11.1 for evaluation and am having a problem converting a CVF V6.6 DLL routine. The problem seems to be matching the calling arguments. In the CVF version the VBA code defines the string variable followed by the string length and the FORTRAN code just includes the string variable. With V11.1 I seem to have to include both the string variable and the string length. With this, I get all of the correct values in the FORTRAN code and I output those values in my test code. But then EXCEL gets an error when the FORTRAN code does the RETURN.

I could not find a specific answer to this in the list of issues in the forum, so I am hopefull someone can straighten me out.

Below is the Code I have in my VBA module, the code in the FORTRAN test file, and the output data generated when the program is run, followed by the error I get from EXCEL.

* * * * * * * * * * * * EXCEL VBA * * * * * * * * * * * *

Dim LngYearToRun As Long

Private Const LngLength1 As Long = 140

Private Const LngLength2 As Long = 150

Private Const LngLength3 As Long = 160

Dim LngValue As Long

Dim StrUserPath1 As String * 160

Dim StrUserPath2 As String * 160

Dim StrUserPath3 As String * 160

Private Declare Sub DISPATCHDLL Lib "H:\\Visual Studio 2008\\Projects\\Dll1\\Dll1\\Release\\DLL1.dll" (LngYearToRun As Long, ByVal StrUserPath1 As String, LngLength1 As Long, ByVal StrUserPath2 As String, LngLength2 As Long, ByVal StrUserPath3 As String, LngLength3 As Long, LngValue As Long)

Sub DealemDLLSub()

LngYearToRun = 2010

LngValue = 256

StrUserPath1 = "User Path Name 1"

StrUserPath2 = "User Path Name 2"

StrUserPath3 = "User Path Name 3"

Cells(7, 1).Value = "Before Call"

Call DISPATCHDLL(LngYearToRun, StrUserPath1, LngLength1, StrUserPath2, LngLength2, StrUserPath3, LngLength3, LngValue)

Cells(9, 1) = Time

Cells(7, 1).Value = "FINISHED"

End Sub

* * * * * * * * * * * * Program * * * * * * * * * * * *

Subroutine DispatchDLL(YearToRunIN,Path1,n1,Path2,n2,Path3,n3,n4)

INTEGER N

INTEGER N1,N2,N3,N4,N5,N6

INTEGER ArrayPointer

INTEGER YearToRunIN, NumUnitsIN, Length

Character (len=140) Path1

Character (len=150) Path2

Character (len=160) Path3

!dec$ attributes dllexport :: DispatchDLL

!dec$ attributes alias : "DISPATCHDLL" :: DispatchDLL

!dec$ attributes stdcall, REFERENCE :: DispatchDLL

OPEN(UNIT=999,FILE='H:\\INTEL\\INTEL_errorlog.dat',STATUS='REPLACE',ERR=991)

WRITE (999,*) 'Before write'

WRITE (999,*) YearToRunIN

WRITE (999,*) TRIM(Path1)

WRITE (999,*) N1

WRITE (999,*) TRIM(Path2)

WRITE (999,*) N2

WRITE (999,*) TRIM(Path3)

WRITE (999,*) N3

WRITE (999,*) N4

WRITE (999,*) 'After write'

CLOSE (999)

RETURN

991 RETURN

END

* * * * * * * * * * * * INTEL_errorlog.dat * * * * * * * * * * * *

Before write

2010

User Path Name 1

140

User Path Name 2

150

User Path Name 3

160

256

After write

* * * * * * * * * * * * EXCEL ERROR * * * * * * * * * * * *

Microsoft Office Excel has encountered a problem and needs to close. We are sorry for the inconvenience.

When I click on Debug I get

An unhandled win32 exception occurred in EXCEL.EXE[2508]

0 Kudos
1 Reply
Steven_L_Intel1
Employee
627 Views
CVF and IVF have different default conventions for string length passing. If you add MIXED_STR_LEN_ARG to the !DEC$ ATTRIBUTES directive for the routine, that should take care of it.
0 Kudos
Reply