replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - DLL basic!
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DLL basic!

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
stenlou



Joined: 24 Jun 2008
Posts: 30
Location: Germany and Denmark

PostPosted: Mon May 13, 2013 1:51 pm    Post subject: DLL basic! Reply with quote

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
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8211
Location: Salford, UK

PostPosted: Tue May 14, 2013 8:30 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Tue May 14, 2013 10:38 am    Post subject: Re: DLL basic! Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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