I have been using the following to open Wordpad:
iRet = WinExec('C:\Program Files\Windows NT\Accessories\wordpad.exe '//Trim(File)//'.txt'//CHAR(0),SW_ShowNormal)
However, if the file name has a space in it it does not work, stopping the file name at the space. Is there a workaround?
Enclose file name with other quote marks. In the above case, use the double-didt quote (") inside the single-didt quote(')
iRet = WinExec('"C:\Program Files\Windows NT\Accessories\wordpad.exe" "'//Trim(File)//'.txt"'//CHAR(0),SW_ShowNormal)
I would think that ShellExecute is a better tool for this, especially if you're hardcoding the path to Wordpad.
WinExec? You could at least use the Fortran standard EXECUTE_COMMAND_LINE.
Thanks Jim, that works fine.
Steve, where do I find the documentation for ShellExecute, I downloaded the pdf from FAQ as you posted but search does not find it or for that matter WinExec?
The documentation is found on MSDN, just look it up with google (actually bing works pretty well for MSDN stuff). For ShellExecute, the MSDN docs says it's in Shell32.dll, so to see what interfaces ifort has made up for you, look in shell32.f90 in the directory that has all the Win32 API interfaces. WinExec is in Kernel32.dll, so the Fortran interface is to be found in kernel32.f90.
Thanks Steve and RO,
I now have the following working:
hwnd = GETHWNDQQ(QWIN$FRAMEWINDOW) iRet = ShellExecute (& hwnd = hwnd, & !!2 lpOperation = "open"C, & !!3 lpFile = Trim(FileName)//CHAR(0), & !!4 lpParameters = NULL_CHARACTER, & !!5 lpDirectory = NULL_CHARACTER, & !!6 nShowCmd = SW_SHOWNORMAL) !!7
Neels, et al
An additional option that can be used is to launch the program using the command line program START (start, Start, ...).
Issue: help start
from a command line
Thanks Steve, I noticed that. You will see the code I used comes directly from the page you linked.
I first tried it in Release mode (my bad) and everything worked, however in Debug mode it complained about the "NULL_CHARACTER" so I changed it to the following:
hwnd = GETHWNDQQ(QWIN$FRAMEWINDOW) iRet = ShellExecute (& hwnd = hwnd, & !!2 lpOperation = "open"C, & !!3 lpFile = Trim(FileName)//CHAR(0), & !!4 lpParameters = "", & !!5 lpDirectory = "", & !!6 nShowCmd = SW_SHOWNORMAL) !!7
Looking in ifwinty.f90, NULL_CHARACTER is defined by:
character, pointer :: NULL_CHARACTER
Is ifwinty.f90 compiled with some switch that results in NULL_CHARACTER's pointer association status being defined at this point? In ifort's implementation
is the same as
NULL_CHARACTER => NULL()
so why isn't NULL_CHARACTER and its brethren initialized in ifwinty.f90?
Looking at the MSDN documentation for ShellExecute, it seems that you should be passing NULL for both lpParameters and lpDirectory (provided you aren't running in 32-bit mode with the -i8 switch active). In the code above, the strings passed aren't NUL-terminated, so anything could happen. Also you are copying an old example; normally
"open" // ACHAR(0)
would be preferable to
Gah! Those NULL_ constants had originally been initialized to NULL(). Not sure what happened here. I think the proper action here is to redeclare these as simply being NULL (the constant zero)( - it should work in most if not all cases. I'm in the middle of updating the API declarations so I will include this. And yes, I'll update the example.