Re: Call by name (in a variable)



jdujic@xxxxxxxxx wrote:
Well, in general, no. Fortran is compiled language, and in general,
call references must be resolved in link time.

On the other hand, Windows offers somewhat similar mechanism for
working with dlls. Maybe Unix has something equivalent, but I'm not
sufficiently versatile with it. Windows API LoadLibrary loads a dll
identified by filename within process' address space, and
GetProcAddress returns the address of a routine identified by exported
name. The only thing to do is to dereference the pointer to the routine
(which, again, is not the easiest thing to do in Fortran, as it's not
portable) and call it.

So, here's non-standard code in Visual Fortran extensions, which calls
2 routines of different name but the same prototype from one dll:

use DFWIN

integer:: hDll
interface
subroutine Any(k)
integer k
end subroutine Any
end interface
pointer (pAny, Any)

hDll = LoadLibrary("MyDll.dll"//char(0))
if (hDll.ne.0) then
pAny = GetProcAddress(hDll, "_ROUTINE1")
if (pAny.ne.0) call Any(42)
pAny = GetProcAddress(hDll, "_ANOTHERROUTINE1")
if (pAny.ne.0) call Any(11)
end if

--
Jugoslav
http://www.xeffort.com


POSIX systems have a similar C library functions called dlopen() and dlsym(). You will have to deal with interfacing the C calls yourself. In both cases, you need to know what your compiler uses for symbol names.

Also, standard Fortran does not have procedure-pointer variables until F2003. Up to F95, you can reference a procedure name, but it is like a constant.

One portable way to do it is to build a list of functions that you want callable by name, and create a procedure-calling subroutine with something like:

select case(sub_name)
case ("abort")
call abort(arg1)
....
end select

I also assume that all procedures have identical argument lists. If not, you have an even bigger challenge.

Joe
.



Relevant Pages

  • Loading multiple assemblies from GAC
    ... a client's machine which references an internal web folder containing ... the main program .dll. ... on the internal web server to further ease versioning difficulties. ... how do I reference dlls in a Windows ...
    (microsoft.public.dotnet.framework.remoting)
  • Excel loses referneces
    ... The problem that I am having is that the workbook that I have created references a ouple of ActiveX DLLs and it seems to sonsistently loose one of the DLL references. ... It will indicate that the DLL is missing when I can find it with Windows Explorer. ... Where does Excel store its refernces to DLL? ...
    (microsoft.public.excel.programming)
  • Re: VB and dlls
    ... applications. ... They are unloaded automatically as Windows detects they are no longer in ... This is true when all references to the objects in the DLL are released, ... the DLL would still show in the module list in tools like PrcView. ...
    (microsoft.public.vb.general.discussion)
  • Re: APPHELP.DLL depndency headache
    ... You're just running regasm on a .NET Dll? ... Phil Wilson [MVP Windows Installer] ... > because it references MSCOREE.DLL, which references SHWAPI.DLL, which ... If you see this warning, ...
    (microsoft.public.dotnet.framework.interop)
  • Re: .Net packaging/wrapper application?
    ... it just didn't work well in reality due to DLL ... Windows works is to look in the executable's directory for a needed DLL ... the way apps used to work when they developed Windows. ... Looks to me like Jim is looking for the .NET equivalent of compiling ...
    (microsoft.public.dotnet.framework.aspnet)