- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When executing, my fortran program needs to automatically popup an URL
How can I do that ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is a fun one. Notice that the above program declares a function with two optional character arguments and that the function has BIND(C). If one doesn't pass an optional argument, the compiler incorrectly passes hidden length values of zero, despite BIND(C) prohibiting hidden arguments.
In most cases, you would not be able to see the effect of this, but on 32-bit Windows and a STDCALL convention, the erroneous hidden arguments change the name decoration leading to link failures. Reported as Intel ticket 05752641.
I've attached a modified version that works in both 32-bit and 64-bit, and also with IFX.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can open a local HTML file, using the user's default browser, with:
call EXECUTE_COMMAND_LINE ("helloworld.html")
This could contain a redirect to a URL. The following Windows program will open the user's default browser to a URL:
program Browser
use, intrinsic :: iso_c_binding
use :: ifwinty
implicit none
! Windows API function AssocQueryString from SHLWAPI.LIB
!DIR$ OBJCOMMENT LIB:"SHLWAPI.LIB"
enum, bind(C) ! ASSOCSTR
enumerator :: ASSOCSTR_COMMAND = 1
enumerator :: ASSOCSTR_EXECUTABLE
enumerator :: ASSOCSTR_FRIENDLYDOCNAME
enumerator :: ASSOCSTR_FRIENDLYAPPNAME
enumerator :: ASSOCSTR_NOOPEN
enumerator :: ASSOCSTR_SHELLNEWVALUE
enumerator :: ASSOCSTR_DDECOMMAND
enumerator :: ASSOCSTR_DDEIFEXEC
enumerator :: ASSOCSTR_DDEAPPLICATION
enumerator :: ASSOCSTR_DDETOPIC
enumerator :: ASSOCSTR_INFOTIP
enumerator :: ASSOCSTR_QUICKTIP
enumerator :: ASSOCSTR_TILEINFO
enumerator :: ASSOCSTR_CONTENTTYPE
enumerator :: ASSOCSTR_DEFAULTICON
enumerator :: ASSOCSTR_SHELLEXTENSION
enumerator :: ASSOCSTR_DROPTARGET
enumerator :: ASSOCSTR_DELEGATEEXECUTE
enumerator :: ASSOCSTR_SUPPORTED_URI_PROTOCOLS
enumerator :: ASSOCSTR_PROGID
enumerator :: ASSOCSTR_APPID
enumerator :: ASSOCSTR_APPPUBLISHER
enumerator :: ASSOCSTR_APPICONREFERENCE
enumerator :: ASSOCSTR_MAX
end enum
interface
function AssocQueryString (flags,str,pszAssoc,pszExtra,pszOut,pcchOut) bind(C,name="AssocQueryStringA")
import
!DIR$ ATTRIBUTES STDCALL :: AssocQueryString
integer(HANDLE) :: AssocQueryString
integer(ENUM), intent(IN), value :: flags !ASSOCF not used here
integer(ENUM), intent(IN), value :: str ! ASSOCSTR
character, dimension(*), intent(IN) :: pszAssoc
character, dimension(*), intent(IN), optional :: pszExtra
character, dimension(*), intent(OUT), optional :: pszOut
integer(DWORD), intent(INOUT) :: pcchOut
end function AssocQueryString
end interface
character(:), allocatable :: browserpath
integer(DWORD) :: pathlen
integer(HANDLE) :: ret
! Get the length of the browser path
ret = AssocQueryString (0,ASSOCSTR_EXECUTABLE,".html"//C_NULL_CHAR,pcchOut=pathlen)
if (ret /= S_FALSE) then
print *, "Could not get path len. Status=",ret
error stop
end if
allocate(character(pathlen)::browserpath)
! Get the path
ret = AssocQueryString (0,ASSOCSTR_EXECUTABLE,".html"//C_NULL_CHAR,pszOut=browserpath,pcchOut=pathlen)
if (ret /= S_OK) then
print *, "Could not get path. Status=",ret
error stop
end if
call EXECUTE_COMMAND_LINE ('"'//browserpath(1:pathlen-1)//'" https://example.com')
end program Browser
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Argh - a compiler bug prevents the program from linking in 32-bit - it works in 64-bit. I'm putting together a simple reproducer for support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is a fun one. Notice that the above program declares a function with two optional character arguments and that the function has BIND(C). If one doesn't pass an optional argument, the compiler incorrectly passes hidden length values of zero, despite BIND(C) prohibiting hidden arguments.
In most cases, you would not be able to see the effect of this, but on 32-bit Windows and a STDCALL convention, the erroneous hidden arguments change the name decoration leading to link failures. Reported as Intel ticket 05752641.
I've attached a modified version that works in both 32-bit and 64-bit, and also with IFX.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much Steve
excatly what I did need and it works fine
Jean-Marc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm glad to hear it. Please mark the desired response as an "answer" to your question, as that will help others.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page