- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using Windows 7 64-bit; Intel Visual Fortran, latest version (11.1.065) within Visual Studio 2008 Professional Edition, and EXCEL 2007.
This is what I did:
1. In Visual Studio, I created a new project for building a Dynamic-link library.
2. I inserted this code:
double precision function pppp(a,b)
!DEC$ ATTRIBUTES STDCALL,REFERENCE,ALIAS:"pppp" :: pppp
double precision a,b
pppp=a*b
return
end
(i.e., I followed most of the recommendations in the that thread.)
3. I then compiled the Release version of the DLL, which produced no errors or warnings. The full path name of the DLL file is "C:\\Work\\For\\pppp\\pppp\\Release\\pppp.dll", which I used in the next step.
4. I opened a new spreadsheet in EXCEL, and in VB I entered the following:
Declare Function pppp Lib "C:\\Work\\For\\pppp\\pppp\\Release\\pppp.dll" (a As Double, b As Double) As Double
Sub test()
a = pppp(2, 3)
End Sub
When I ran it, it produced the same error the original poster got, namely:
Runtime error '453'
Can't find DLL entry point pppp in C:\\Work\\For\\pppp\\pppp\\Release\\pppp.dll
I don't know how to get around this. Can anybody help??
Thanks in advance,
Bruno Repetto, PhD
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My code includes:
VBA:
Private Declare Sub WaterDensity_F Lib "AWAProps.dll" _
(TempC As Double, Value As Double, ByVal Units As String)
Note the ByVal is required to return the character string.
The variable declares are:
Dim Units As String * 20
Dim Value As Double
and then for the actual call:
Call WaterDensity_F(T, Value, Units)
Fortran:
Subroutine WaterDensity_F(TempC, Value, Units)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, ALIAS:'WaterDensity_F' :: WaterDensity_F
!DEC$ ATTRIBUTES REFERENCE :: Units
IMPLICIT NONE
Real(KIND=8), INTENT(IN) :: TempC(1)
Real(KIND=8), INTENT(OUT) :: Value(1)
Character(LEN=20), INTENT(INOUT) :: Units
Note the use of Arrays here. I think this helps because Fortran uses the location not the variable value. Also, note that Units has REFERENCE here, which in VBA it is ByVal.
The ALIAS ensures that the entry point is appropriately decorated and the case preserved for VBA.
the _F on the routine names is not required, but I use it because on the Fortran side, this is a wrapper function which is only used for the VBA entry. The "real" function names are used as entry points for other Fortran calls.
Regards.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does the EXCEL sample provided in Samples\en_US\MixedLanguage.zip build and run for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried your example (filling in for missing instructions with dummy stuff), and it worked!!
So now that I had something that actually worked, I went back to what I had done before and to my embarrassment I found that the DLLEXPORT was missing! In my confusion I didn't notice I had doen away with it. I put it back and everything fell into place quite neatly. I can call my "pppp" function in VB, as well as call it a user-defined function in an EXCEL worksheet.
Thank you very much David!!
Just the little push that I needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does the EXCEL sample provided in Samples\en_US\MixedLanguage.zip build and run for you?
Thanks, Steve!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page