Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Windows API (SHFileOperation)

lou-muccioli
Beginner
1,854 Views

Hi,

I'm getting a crash when I call SHFileOperation and I suspect it may have something to do with the sh.pFrom structure member which is defined as INTEGER (LPCSTR) in INFWINTY.F90. Any help would be greatly appreciated.

Program DelDirRecursive

USE IFPORT
USE IFWIN

implicit none

character*256 cString
integer ierr, kerr
TYPE (T_SHFILEOPSTRUCT) sh
cString = ' '
sh.hwnd = NULL
sh.wFunc = FO_DELETE
sh.pFrom = 'ABC'C
sh.pTo = NULL
sh.fFlags = FOF_SILENT
sh.fAnyOperationsAborted = NULL
sh.hNameMappings = 0
sh.lpszProgressTitle = NULL
ierr = SHFileOperation (sh)
if (ierr .ne. 0) print *,' I/O Error'
if (ierr .eq. 0) print *,' Success'
stop
end

0 Kudos
4 Replies
Robert_van_Amerongen
New Contributor III
1,854 Views
Dear Lou, I read your problem and read the SDK for the SHFILEOPSTRUCT structure. There I found that both the members pFrom and pTo must be double NULL-terminated. See the explicit warning at: http://msdn.microsoft.com/en-us/library/windows/desktop/bb759795(v=vs.85).aspx Maybe this helps? Robert
0 Kudos
lou-muccioli
Beginner
1,854 Views
Hi Robert, Yes, I seen that as well but can't seem to nail down the correct syntax to make it double null terminated. Lou
0 Kudos
IanH
Honored Contributor III
1,854 Views
To append two nulls to a string you could do something like: [fortran] string_with_two_nulls = 'abc' // achar(0) // achar(0) [/fortran] The ISO_C_BINDING intrinsic module provides the C_NULL_CHAR constant that is more or less equivalent to ACHAR(0).
0 Kudos
lou-muccioli
Beginner
1,854 Views
This seems to do the trick. Now, the "real" program passes in the directory name as "fdir(1:leng)" and I'm having trouble getting that to work but I'll keep debugging. Program DelDir USE IFPORT USE IFWIN implicit none character*256 cString integer ierr, kerr TYPE (T_SHFILEOPSTRUCT) sh character(512) :: file_spec = "ABC"C//""C ! double null terminator sh.hwnd = NULL sh.wFunc = FO_DELETE sh.pFrom = loc (file_spec) ! Added this sh.pTo = NULL sh.fAnyOperationsAborted = NULL sh.fFlags = FOF_NOCONFIRMATION sh.hNameMappings = 0 sh.lpszProgressTitle = NULL ierr = SHFileOperation (sh) if (ierr .ne. 0) kerr=-1 if (ierr .eq. 0) kerr=0 stop end
0 Kudos
Reply