Windows API (SHFileOperation)

Windows API (SHFileOperation)

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

5 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

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

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

To append two nulls to a string you could do something like:


   string_with_two_nulls = 'abc' // achar(0) // achar(0)

The ISO_C_BINDING intrinsic module provides the C_NULL_CHAR constant that is more or less equivalent to ACHAR(0).

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

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!