- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
and got the following error when I tried to run it in Xcel 2003 (11.8231.8221) SP3
Runtime error!
Program c:\programfiles\microsoft office\office11\excel.exe
R6034 an application has made an attempt to load the C runtime librarys incorrectly.
and when I click OK i get anoter Microsoft visual basic run time error '48' file not found t:\ses\test2\fcall.dll.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I haven't seen the first error before, though...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I haven't seen the first error before, though...
Yes I changed the path which shows up in the second error. I looked on the web and found that if I use
ifort /dll FortranDLL.f90 /MT it works OK. My question now is what is really needed in the fortran
subroutine FortranCall (r1, num)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"FortranCall" :: FortranCall
integer, intent(in) :: r1
character(10), intent(out) :: num
!DEC$ ATTRIBUTES REFERENCE :: num
num = ''
write (num,'(i0)') r1 * 2
return
end subroutine FortranCall
My fortran is
c234567
subroutine SUNDCALC(x, y,i,res)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"SUNDCALC" :: SUNDCALC
c !DEC$ ATTRIBUTES REFERENCE :: num
real*8 x,y
integer i
real*8 res
if(i.eq.0)then
res=x+y
else
res=x-y
endif
return
end
which doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am building the fortran in F77 and no matter what I do I get the error in excel. I have documented the error and would like to send you the fortran77 and the 2003 excel file. What I want to do is use the Fortran77 calculation module which transfers 2 real values in and returns 1 real back. If I have to do it in Fortran90 that will be OK but I am not that fluent in Fortran 90. So can I email you my simple code and xcel or get another examplethat does what I want?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well here goes.
I am attaching the excel file with the VBA code included which references the sundcalc.for program and the fortran files in a zip file.
Option Explicit
Public Declare Sub SUNDCALC Lib "D:Documents and Settingse039373My DocumentsTZtestsundcalc.dll" _
(ByRef x As Double, ByRef y As Double, ByRef i As Long, ByRef res As Double)
and
Private Sub CommandButton1_Click()
Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double
x = Range("var1").Value
y = Range("var2").Value
i = Range("flag").Value
Call SUNDCALC(x, y, i, res)
Range("result").Value = res
End Sub
I also included what I think should be the reqired
cDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"SUNDCALC" :: SUNDCALC to the
fortran file. sundcalc.for
What I am trying todo is get this simple example to work. It takes two real numbers X1 and X2 and an integer flag as input. Based on an integer flag the subroutineadds the two reals or subtracts the two reals and then returns the result.
I have built this in Compaq VF 6.x and it works fine. However, Compaq VF requires a .def file which I included in the attached zip file.
Also, I found that for the example in the included samples that comes with intel Visual fortran to make it work I must compile using
ifort /dll Fcall/MT to make the sample work. I used this compilation command to compile sundcalc.
I also noticed that the sample creates the following files .dll, .exp,.lib,*obj
but my program creates .dll,.dll.manifest, and .obj.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In version 10.0 (unsupported), there is just a Visual Studio solution for the Excel sample. In version 11 a build.bat file is also provided illustrating building from the command line.
That you do not get a .exp and .lib indicates that you have not named a routine in a DLLEXPORT directive.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
subroutine SUNDCALC(x, y,i,res)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"SUNDCALC" :: SUNDCALC
!DEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
if(i.eq.0)then
res=x+y
else
res=x-y
endif
return
end subroutine SUNDCALC
I do not use a DEF file. I then used the attached EXCEL file Book1.xls to test it. I Declare the DLL in a module thus
Option Explicit
Public Declare Sub SUNDCALC Lib "SUNDCALC.DLL" _
(ByRef x As Double, ByRef y As Double, ByRef i As Long, ByRef res As Double)
and add the Excel file to the Release or Debug folder that contains the DLL so that it can find it (otherwise add it to the c:windowssystem32 folder or somewhere in your default search path), whichever DLL you want to test.
The Visual basic code is
Private Sub CommandButton1_Click()
Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double
x = Range("var1").Value
y = Range("var2").Value
i = Range("flag").Value
Call SUNDCALC(x, y, i, res)
Range("result").Value = res
End Sub
Private Sub CommandButton2_Click()
Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double
x = Range("VAR3").Value
y = Range("VAR4").Value
i = Range("flag2").Value
Call SUNDCALC(x, y, i, res)
Range("res2").Value = res
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
subroutine SUNDCALC(x, y,i,res)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"SUNDCALC" :: SUNDCALC
!DEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
if(i.eq.0)then
res=x+y
else
res=x-y
endif
return
end subroutine SUNDCALC
I do not use a DEF file. I then used the attached EXCEL file Book1.xls to test it. I Declare the DLL in a module thus
Option Explicit
Public Declare Sub SUNDCALC Lib "SUNDCALC.DLL" _
(ByRef x As Double, ByRef y As Double, ByRef i As Long, ByRef res As Double)
and add the Excel file to the Release or Debug folder that contains the DLL so that it can find it (otherwise add it to the c:windowssystem32 folder or somewhere in your default search path), whichever DLL you want to test.
The Visual basic code is
Private Sub CommandButton1_Click()
Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double
x = Range("var1").Value
y = Range("var2").Value
i = Range("flag").Value
Call SUNDCALC(x, y, i, res)
Range("result").Value = res
End Sub
Private Sub CommandButton2_Click()
Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double
x = Range("VAR3").Value
y = Range("VAR4").Value
i = Range("flag2").Value
Call SUNDCALC(x, y, i, res)
Range("res2").Value = res
End Sub
Thanks! It works like a charm in IVF 10.x I used the ifort /dl sundcalc.f90 /MT command and everything is fine.
I just needed a small example to have as a base for my real application.
Thanks again.
steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! It works like a charm in IVF 10.x I used the ifort /dl sundcalc.f90 /MT command and everything is fine.
I just needed a small example to have as a base for my real application.
Thanks again.
steve
I have one more problem now. Most of my existing Fortran and the application I want to link with Excel is written in Fortran 77. I have tried to modify anthonyrichardsfortran to be Fortran 77 but I now I can not get the interface to work See below. My question is can I create the driver program i.e. SUNDCALC in f90 (sundcalc.f90) which then calls a subroutine written in Fortran 77?
When I compile this as ifort /dll sundcalc.for /MT it gives many errors (see attached)
cDEC$ NOFREEFORM
cDEC$ FIXEDFORMLINESIZE:72
subroutine SUNDCALC(x, y,i,res)
cDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:'SUNDCALC' :: SUNDCALC
cDEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
call sundcalc2(x,y,i,res)
end
c
subroutine sundcalc2(xx,yy,ii,ress)
real*8 xx,yy,ress
integer ii
c
if(ii.eq.0)then
ress=xx+yy
else
ress=xx-yy
endif
c
return
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have one more problem now. Most of my existing Fortran and the application I want to link with Excel is written in Fortran 77. I have tried to modify anthonyrichards fortran to be Fortran 77 but I now I can not get the interface to work See below. My question is can I create the driver program i.e. SUNDCALC in f90 (sundcalc.f90) which then calls a subroutine written in Fortran 77?
When I compile this as ifort /dll sundcalc.for /MT it gives many errors (see attached)
cDEC$ NOFREEFORM
cDEC$ FIXEDFORMLINESIZE:72
subroutine SUNDCALC(x, y,i,res)
cDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:'SUNDCALC' :: SUNDCALC
cDEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
call sundcalc2(x,y,i,res)
end
c
subroutine sundcalc2(xx,yy,ii,ress)
real*8 xx,yy,ress
integer ii
c
if(ii.eq.0)then
ress=xx+yy
else
ress=xx-yy
endif
c
return
end
First, there isn't the distinction between Fortran77 and Fortran90 that you think. Fortran77 is contained within Fortran90, in the sense that a Fortran90 (or later) compiler like ifort will compile almost any Fortran77 program. So you really don't need to do anything to the code that Anthony supplied.
Second, why are you calling sundcalc2 from sundcalc, instead of just doing the calculation in sundcalc? You might think you have a F90 driver program calling a F77 subroutine, but actually all the code is F77 and also F90 (except for the following point). The file extension determines what assumptions the compiler makes, for all the code in the file.
Third, despite the unnecessariness, the code that you show compiles happily with the file name sundcalc.for. I think you actually named it sundcalc.f90 and tried to compile it with 'ifort sundcalc.f90 ...' This does indeed give errors, but if you change each 'cDEC$ ' to '!DEC$ ' to make it Fortran90 conforming, all is OK.
But, to repeat, this is all unnecessary. You can build a program with a mix of .for and .f90 files, although I'd recommend switching over fully to .f90, to get access to the powerful new features of Fortran90.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The primary advantage of free-form source is that some classic Fortran coding errors can't be made in free-form source, such as characters dropped after column 72 and errors not diagnosed because blanks are not significant.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The primary advantage of free-form source is that some classic Fortran coding errors can't be made in free-form source, such as characters dropped after column 72 and errors not diagnosed because blanks are not significant.
Yep, some of your lines are longer than 72 columns! Use Freeform!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The primary advantage of free-form source is that some classic Fortran coding errors can't be made in free-form source, such as characters dropped after column 72 and errors not diagnosed because blanks are not significant.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to all for your comments but here is my situation.
I agree that f90 has some usefull extensions but Ihave quite a bit of legacy code that is in Fortran77 that works great as an executable. What I am trying to do isuse Excel 2003 as a front end to some of theseFortran programs and want to create a DLL to call Fortran. The problem I was seeing was that when I compiled the F77 (.for) it would give me errors on all the lines with c in column 1. All the legacy code has c in column 1 so I had to fix this.
I tried all your suggestions and I finally got it to compile and work as a DLL assundcalc.for (see below)
the compile line was ifort /dll sundcalc.for /MT
;
cDEC$ NOFREEFORM
cDEC$ FIXEDFORMLINESIZE:132
c234567
subroutine SUNDCALC(x, y,i,res)
c
cDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:'SUNDCALC' :: SUNDCALC
cDEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
if(i.eq.0)then
res=x+y
else
ress=x-y
endif
c
return
end
c
Again thanks for all the help.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page