 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
stenlou
Joined: 24 Jun 2008 Posts: 30 Location: Germany and Denmark
|
Posted: Mon May 13, 2013 1:51 pm Post subject: DLL basic! |
|
|
Anybody help with a quick note on how to create a DLL, how to make it like a plugin available only when the DLL is installed/added.
In other word. I have a fortran .exe and want to for some installation to provide extra options (via a dll) but also want to make sure that the .exe runs with (and without the DLL).
NEVER done this so I just need some basic help/explanation of workflow (an example would be great)
Sten |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8211 Location: Salford, UK
|
Posted: Tue May 14, 2013 8:30 am Post subject: |
|
|
Presumably you are writing in Fortran using FTN95.
Are you working from
a) Plato or
b) Visual Studio or
c) A command line?
Are you using
a) Win32 or
b) .NET? |
|
Back to top |
|
 |
jalih
Joined: 30 Jul 2012 Posts: 196
|
Posted: Tue May 14, 2013 10:38 am Post subject: Re: DLL basic! |
|
|
stenlou wrote: | how to make it like a plugin available only when the DLL is installed/added. |
At first using LoadLibrary() and GetProcAddress() winapi calls comes to mind. Problem is that Fortran 95 don't have procedure pointers. Maybe there is some trick to overcome that limitation? My Fortran skills are little bit limited but maybe someone more skilled could provide the answer?
Fortran 2003 makes this kind of things easy. Below is a Fortran 2003 sample to call procedure named hello that takes no parameters from test.dll.
Code: |
module load_dll
use, intrinsic :: iso_c_binding, only: c_f_procpointer, c_funptr, c_intptr_t, &
c_null_char, c_char, c_associated
implicit none
interface
function LoadLibrary(lpFileName) bind(C, name='LoadLibraryA')
use, intrinsic :: iso_c_binding, only: c_intptr_t, c_char
character(kind=c_char) :: lpFileName(*)
!GCC$ ATTRIBUTES STDCALL :: LoadLibrary
integer(c_intptr_t) :: LoadLibrary
end function LoadLibrary
function GetProcAddress(hModule, lpProcName) bind(C, name='GetProcAddress')
use, intrinsic :: iso_c_binding, only: c_funptr, c_intptr_t, c_char
!GCC$ ATTRIBUTES STDCALL :: GetProcAddress
type(c_funptr) :: GetProcAddress
integer(c_intptr_t), value :: hModule
character(kind=c_char) :: lpProcName(*)
end function GetProcAddress
end interface
end module load_dll
module my_dll
use, intrinsic :: iso_c_binding, only: c_f_procpointer, c_funptr, c_intptr_t, &
c_null_char, c_char, c_associated
implicit none
abstract interface
subroutine hello() bind(C)
end subroutine hello
end interface
integer(c_intptr_t) :: module_handle
type(c_funptr) :: proc_address
procedure(hello), bind(C), pointer :: my_proc
end module my_dll
program main
use load_dll
use my_dll
implicit none
module_handle = LoadLibrary(c_char_'test.dll'//c_null_char)
if (module_handle == 0) stop 'Can''t load the DLL'
proc_address = GetProcAddress(module_handle, c_char_'hello'//c_null_char)
if (.not. c_associated(proc_address)) stop 'Can''t obtain the procedure address'
call c_f_procpointer(proc_address, my_proc)
call my_proc
end program main
|
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|