Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entry point into *.dll 1

Status
Not open for further replies.

BFG2

Technical User
Feb 4, 2003
23
0
0
GB
Hi,

Am presently using Compaq Visual Fortran (or trying to use it) to create a function that is compiled as a dll. The plan is then to use Excel XP to call this function.

Originally I was using VBA in Excel to do the calcs (which at the time was adequate), although now Fortran dlls is what is required by my boss. Could someone just give me quick bit of Fortran code to perform the Sine of a number for example, and then the VBA command to define the function in Excel? I can hopefully go on from there to do the calcs that are required - just an example of calling a dll would be great.

Any help on this would be appreciated as I keep getting "Can't find entry point"/Excel crashes amongst other things and I'm starting to tear my hair out!!!!

Many thanks,

BFG
 
Please find hereafter an axample of a VBA code calling a Fortran DLL that returns the value of PI.

VBA code:

[tt]Declare Function GETPI Lib "GETPI" () As Double

Function GetPiValue() As Double
GetPiValue = GETPI()
End Function[/tt]


Fortran code:

[tt] REAL*8 FUNCTION GetPI()
!DEC$ ATTRIBUTES DLLEXPORT :: GetPI
IMPLICIT NONE
GetPI = ACOS(-1.D0)
RETURN
END[/tt]

It works without declaring the naming convention because both VBA and Fortran uses STDCALL convention. If you want to change it you need to add attributes on both import and export declarations (see VBA and VisualFortran Help).

I hope this small code will help you
 
Phil,

Thanks for the quick reply. Much appreciated, and its interesting to finally see a bit of code that actually works!!! Just one final question - how could I pass a value to the dll , manipulate it (say for example multiply it by pi in this case) and pass it back.

Thanks for the help.
 
The following code will do what you want.

VBA code:

[tt]Declare Function GETPI Lib "GETPI" (X As Double) As Double

Function GetPiValue(arg As Variant) As Double
Dim X As Double
X = arg
GetPiValue = GETPI(X)
End Function[/tt]


Fortran code:

[tt] REAL*8 FUNCTION GetPI(X)
!DEC$ ATTRIBUTES DLLEXPORT :: GetPI
IMPLICIT NONE
REAL(8) X
GetPI = ACOS(-1.D0)*X
RETURN
END[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top