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)
Jim Dempsey
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
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
call C_F_POINTER(C_NULL_PTR,NULL_CHARACTER)
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
"open"c
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.
