gfxgfx
 
Please login or register.

Login with username, password and session length
 
gfx gfx
gfx
1617 Posts in 535 Topics by 779 Members - Latest Member: rhoronjeff@comcast.net November 27, 2022, 07:54:24 PM
*
gfx* Home | Help | Search | Login | Register | gfx
gfx
Absoft User Forum  |  Support  |  General  |  Question about Creating DLL's Technical / White Paper
gfx
gfxgfx
 

Author Topic: Question about Creating DLL's Technical / White Paper  (Read 5231 times)

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Question about Creating DLL's Technical / White Paper
« on: May 24, 2010, 12:19:11 AM »
Folks:

1. The routine CALCULATE is in a DLL.
The White Paper shows how to call this correctly from VB.
How do I call this correctly from Absoft FORTRAN?

STDCALL SUBROUTINE CALCULATE(A, B, C, RESULT)
IMPLICIT NONE
DOUBLE PRECISION A,B,C,RESULT
RESULT = A + B + C
RETURN
END

2. If CALCULATE is in a third-party .DLL (no .LIB or .OBJ) and is not available at link-time, but is late-loaded using LoadLibrary and GetProcAddress, then how do I call this correctly from Absoft FORTRAN?

forumadmin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 333
Re: Question about Creating DLL's Technical / White Paper
« Reply #1 on: May 24, 2010, 11:59:04 AM »
1.      EXTERNAL CALCULATE
         STDCALL CALCULATE
         CALL CALCULATE (A,B,RESULT)

See also C:\Absoft11.0\examples\DLL

2. You won't be able use the address directly in the routine that obtains it from GetProcAddress. However, you can pass it to another subprogram that declares it as external.

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: Question about Creating DLL's Technical / White Paper
« Reply #2 on: June 06, 2010, 01:14:49 AM »
Here is an example of an STD call to a user-written function.

DialogBox is a Windows Dialog Box function in User32.dll referenced through User32.lib
MySTD is my user-written message-processor function for the Dialog Box

       integer(kind=4), external, stdcall :: DialogBox, MySTD@16
! the @16 is needed because the compiler does not know that MySTD function has 4 integer*4 parameters.

      .......
      retcode = DialogBox (val(g_hInstance), val(IDD_MyDialogBox), val(hWnd), MySTD@16)
      ......

then

        logical stdcall function MySTD (hDlg, message, wParam, lParam)
! now the compiler does know that MySTD has 4 integer*4 parameters

        integer hDlg;    value hDlg
        integer message; value message
        integer wParam;  value wParam
        integer lParam;  value lParam

       .....

        MySTD = .TRUE.

       end

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: Question about Creating DLL's Technical / White Paper
« Reply #3 on: July 26, 2010, 06:05:44 AM »
http://www.absoft.com/literature/DLLs.pdf describes the process of creating a DLL.
It states:
Three files will be created with the following extensions:
.dll       the dynamic load library
.lib       the import library (see below)
.exp     the export file used by LINK

Using the -dll option in Absoft 11.0.3, I obtain the .lib and the .exp files, but not the .dll file.

Later: Solved this one myself:  the "Target type" in Project Options must be DLL
« Last Edit: July 26, 2010, 06:18:30 AM by Mike Linacre »

Absoft User Forum  |  Support  |  General  |  Question about Creating DLL's Technical / White Paper
 

gfxgfx
gfx gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!